home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SNNSV32.ZIP / SNNSv3.2 / kernel / sources / kr_io.c < prev    next >
C/C++ Source or Header  |  1994-04-25  |  80KB  |  3,169 lines

  1. /*****************************************************************************
  2.   FILE           : kr_io.c
  3.   SHORTNAME      : kr_io.c
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : SNNS-Kernel User Interface File I/O
  7.   NOTES          :
  8.  
  9.   AUTHOR         : Niels Mache
  10.   DATE           : 28.05.90
  11.  
  12.   CHANGED BY     : Michael Vogt, Guenter Mamier
  13.   IDENTIFICATION : @(#)kr_io.c    1.30 4/18/94
  14.   SCCS VERSION   : 1.30
  15.   LAST CHANGE    : 4/18/94
  16.  
  17.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  18.  
  19. ******************************************************************************/
  20. #include <stdlib.h>
  21. #include <time.h>
  22. #include <string.h>
  23. #include <ctype.h>
  24. #include <memory.h>
  25. #include <stdarg.h>
  26. #include <stdio.h>
  27.  
  28. #include "kr_typ.h"     /*  Kernel Types and Constants  */
  29. #include "kr_const.h"     /*  Constant Declarators for SNNS-Kernel  */
  30. #include "kr_def.h"     /*  Default Values  */
  31.  
  32. #include "kr_ui.h"     /*  Interface Functions  */
  33. #include "kernel.h"      /*  Function Prototypes */
  34. #include "kr_mac.h"     /*  Kernel Macros  */
  35. #include "version.h"     /*  Version and Patchlevel  */
  36. #include "dlvq_learn.h"
  37. #include "kr_io.ph"     /*  Function Prototypes */
  38. #include "kr_newpattern.h" /*pattern handling functions */
  39.  
  40. #ifdef ultrix
  41. #define retchk( ret_code )  if ((ret_code) == EOF)  return( KRERR_IO )
  42. #define RETCHKGTO( ret_code )  if ((ret_code) == EOF)  goto end
  43. #else
  44. #define retchk( ret_code )  if ((ret_code) < 0)  return( KRERR_IO )
  45. #define RETCHKGTO( ret_code )  if ((ret_code) < 0)  goto end
  46. #endif
  47.  
  48. /*****************************************************************************
  49.   FUNCTION : mstrcat 
  50.  
  51.   PURPOSE  : 
  52.   NOTES    : mstrcat is called
  53.              mstrcat( dest, src1, src2, ... , (char *) 0 )
  54.  
  55.   RETURNS  :
  56.   UPDATE   : 
  57. ******************************************************************************/
  58. static void  mstrcat(char *va_alist,...)
  59.  
  60. {
  61.   va_list  args;
  62.   char      *dest, *src;
  63.  
  64.  
  65.   va_start( args, va_alist );
  66.   if ((dest = va_alist) == (char *) 0)  return;
  67.  
  68.   while ((src = va_arg( args, char * )) != (char *) 0)
  69.     strcat( dest, src );
  70.  
  71.   va_end( args );
  72. }
  73.  
  74. /*****************************************************************************
  75.   FUNCTION : mstrcpy 
  76.  
  77.   PURPOSE  : 
  78.   NOTES    : mstrcpy is called
  79.              mstrcpy ( dest, src1, src2, ... , (char *) 0 )
  80.  
  81.   RETURNS  :
  82.   UPDATE   : 
  83. ******************************************************************************/
  84. static void  mstrcpy(char *va_alist,...)
  85. {
  86.   va_list  args;
  87.   char      *dest, *src;
  88.  
  89.  
  90.   va_start( args, va_alist );
  91.   if ((dest = va_alist) == (char *) 0)  return;
  92.   if ((src  = va_arg( args, char * )) == (char *) 0)  return;
  93.   while( *src != EOS )
  94.     *dest++ = *src++;
  95.  
  96.   while ((src = va_arg( args, char * )) != (char *) 0)
  97.     {
  98.     while( *src != EOS )
  99.       *dest++ = *src++;
  100.   }
  101.  
  102.   va_end( args );
  103.  
  104.   *dest = EOS;
  105. }
  106.  
  107.  
  108. /*****************************************************************************
  109.   FUNCTION : krio_getIOVersion
  110.  
  111.   PURPOSE  : returns the current file I/O version number
  112.   NOTES    :
  113.  
  114.   RETURNS  :
  115.   UPDATE   : 
  116. ******************************************************************************/
  117. static char  *krio_getIOVersion(void)
  118. {
  119.   static char    io_version[128];
  120.  
  121.   strcpy( io_version, NETFILE_VERSION );
  122. #ifdef KERNEL3D
  123.   strcat( io_version, KERNEL3D_NETFILE_VERSION );
  124. #endif
  125.  
  126.   return( io_version );
  127. }
  128.  
  129.  
  130. /*#################################################
  131.  
  132. GROUP: Kernel File Output Functions
  133.  
  134. #################################################*/
  135.  
  136. /*****************************************************************************
  137.   FUNCTION : krio_writeHeader
  138.  
  139.   PURPOSE  : 
  140.   NOTES    :
  141.  
  142.   RETURNS  :
  143.   UPDATE   : 
  144. ******************************************************************************/
  145. static krui_err  krio_writeHeader(char *version, char *net_name)
  146. {
  147.   long  clock;
  148.   int   err;
  149.   int   no_of_sites,
  150.         no_of_STable_entries,
  151.         no_of_FTable_entries;
  152.  
  153.  
  154.   krui_getNetInfo( &no_of_sites, &NoOfLinks, &no_of_STable_entries,
  155.            &no_of_FTable_entries );
  156.   units_have_sites = no_of_sites > 0;
  157.  
  158.   clock = 1;
  159.   (void) time( (time_t *) &clock);
  160.  
  161.   err = fprintf( file_out, "%s %s\n%s %s\n%s : ",
  162.                 title[0], version, title[1], 
  163.         ctime( (time_t *) &clock), title[2] );
  164.   retchk( err );
  165.  
  166.   if (net_name == NULL)
  167.     err = fprintf( file_out, "UNTITLED\n" );
  168.   else
  169.     err = fprintf( file_out, "%s\n", net_name );
  170.  
  171.   retchk( err );
  172.   err = fprintf( file_out, "%s :\n%s : %i\n%s : %i\n%s : %i\n%s : %i\n",
  173.                 title[14],
  174.                 title[3], NoOfUnits,
  175.                 title[4], NoOfLinks,
  176.                 title[5], no_of_FTable_entries,
  177.                 title[6], no_of_STable_entries );
  178.  
  179.   retchk( err );
  180.  
  181.   err = fprintf( file_out, "\n\n%s : %s\n",
  182.                 title[7], krui_getLearnFunc() );
  183.   retchk( err );
  184.   err = fprintf( file_out, "%s   : %s\n",
  185.                 title[16], krui_getUpdateFunc() );
  186.   retchk( err );
  187.  
  188.   return( KRERR_NO_ERROR );
  189. }
  190. /*****************************************************************************
  191.   FUNCTION : krio_cutTrailingZeros
  192.  
  193.   PURPOSE  : cut all trailing '0'  
  194.   NOTES    :
  195.  
  196.   RETURNS  :
  197.   UPDATE   : 
  198. ******************************************************************************/
  199. static void krio_cutTrailingZeros(char *string)
  200. {
  201.     int j;
  202.  
  203.  
  204.     if (*string == EOS)  return;
  205.     for (j = strlen( string ) - 1; ((string[j] == '0') && (j > 0)); j--) {}
  206.  
  207.     if (string[j] == '.')
  208.       string[j] = EOS;
  209.     else
  210.       string[j + 1] = EOS;
  211. }
  212.  
  213. /*****************************************************************************
  214.   FUNCTION : krio_repchar 
  215.  
  216.   PURPOSE  : 
  217.   NOTES    : 
  218.  
  219.   RETURNS  : 
  220.   UPDATE   : 
  221. ****************************************************************************/
  222. static char  *krio_repchar(char c, int N)
  223. {
  224.   int   i;
  225.   static char  str[180];
  226.  
  227.   if ( (N - 1) >= sizeof (str))   N = sizeof (str) - 1;
  228.  
  229.   for (i = 0; i < N; i++)
  230.     str[ i ] = c;
  231.  
  232.   str[N] = 0;
  233.   return( str );
  234. }
  235.  
  236. /*****************************************************************************
  237.   FUNCTION : krio_stringLimits 
  238.  
  239.   PURPOSE  : 
  240.   NOTES    : 
  241.  
  242.   RETURNS  : 
  243.   UPDATE   : 
  244. ******************************************************************************/
  245.  
  246.  
  247. static void  krio_stringLimits(void)
  248. {
  249.   char  *symbol, *name;
  250.   int   sym_type,
  251.         unit_no,
  252.     len, i1, i2, i3, i4, i5,
  253.     subnet_no, layer_no;
  254.   FlintType  act, bias;
  255.   int    st;
  256.   char    *def_act_func,    *def_out_func;
  257.  
  258.   struct  PosType   pos;
  259.   bool      neg1, neg2, neg3;
  260.  
  261.  
  262.   unit_name_len = site_name_len = type_name_len = 0;
  263.   out_func_len = act_func_len = site_func_len = 0;
  264.   def_out_func_len = def_act_func_len = 0;
  265.  
  266.   /*  get default subnet and layer numbers  */
  267.   krui_getUnitDefaults( &act, &bias, &st, &subnet_no, &layer_no,
  268.             &def_act_func, &def_out_func );
  269.  
  270.   if ( krui_getFirstSymbolTableEntry( &symbol, &sym_type) )  {
  271.     do  {
  272.       len = strlen( symbol );
  273.  
  274.       switch (sym_type)  {
  275.         case  UNIT_SYM:
  276.             unit_name_len = Max( unit_name_len, len );
  277.             break;
  278.         case  SITE_SYM:
  279.             site_name_len = Max( site_name_len, len );
  280.             break;
  281.         case  FTYPE_UNIT_SYM:
  282.             type_name_len = Max( type_name_len, len );
  283.       }
  284.     }
  285.     while ( krui_getNextSymbolTableEntry( &symbol, &sym_type ) );
  286.   }
  287.  
  288.   unit_no = krui_getFirstUnit();
  289.   do  {
  290.     symbol = krui_getUnitOutFuncName( unit_no );
  291.     if (strcmp( symbol, def_out_func ) != 0)
  292.       out_func_len = Max( out_func_len, strlen( symbol ));
  293.  
  294.     symbol = krui_getUnitActFuncName( unit_no );
  295.     if (strcmp( symbol, def_act_func ) != 0)
  296.       act_func_len = Max( act_func_len, strlen( symbol ));
  297.   }
  298.   while ((unit_no = krui_getNextUnit() ) != 0);
  299.  
  300.  
  301.   def_out_func_len = strlen( def_out_func );
  302.   def_act_func_len = strlen( def_act_func );
  303.  
  304.   if (krui_getFirstSiteTableEntry( &name, &symbol ))  {  
  305.     do
  306.       site_func_len = Max( site_func_len, strlen( symbol ));
  307.     while (krui_getNextSiteTableEntry( &name, &symbol ));
  308.   }
  309.  
  310.   unit_no = krui_getFirstUnit();
  311.  
  312.   neg1 = neg2 = neg3 = is_subnet_info =
  313.   is_layer_info = FALSE;
  314.   i1 = i2 = i3 = 0;
  315.  
  316.   do  {
  317.     krui_getUnitPosition( unit_no, &pos );
  318.     i1 = Max( i1, abs( pos.x ) );
  319.     i1 = Max( i1, abs( pos.y ) );
  320.     if (pos.x < 0) neg1 = TRUE;
  321.     if (pos.y < 0) neg1 = TRUE;
  322.  
  323.     i5 = krui_getUnitSubnetNo( unit_no );
  324.     if (i5 < 0) neg2 = TRUE;
  325.     i2 = Max( i2, abs( i5 ) );
  326.     if (i2 != subnet_no)  is_subnet_info = TRUE;
  327.  
  328.     i4 = (int) krui_getUnitLayerNo( unit_no );
  329.     if (i4 < 0) neg2 = TRUE;
  330.     i3 = Max( i3, abs( i4 ) );
  331.     if (i3 != layer_no) is_layer_info = TRUE;
  332.   }
  333.   while ( (unit_no = krui_getNextUnit() ) > 0);
  334.  
  335.   pos_no_len = 1;
  336.   while ( (i1 /= 10) != 0)
  337.     ++pos_no_len;
  338.   if (neg1)  pos_no_len++;
  339.  
  340.   subnet_no_len = 1;
  341.   while ( (i2 /= 10) != 0)
  342.     ++subnet_no_len;
  343.   if (neg2)  subnet_no_len++;
  344.  
  345.   layer_no_len = 1;
  346.   while ( (i3 /= 10) != 0)
  347.     ++layer_no_len;
  348.   if (neg3)  layer_no_len++;
  349.  
  350.   len = NoOfUnits;
  351.   unit_no_len = 1;
  352.   while ( (len /= 10) != 0)
  353.     ++unit_no_len;
  354.  
  355. }
  356.  
  357.  
  358. /*****************************************************************************
  359.   FUNCTION : krio_fmtShapeing
  360.  
  361.   PURPOSE  : 
  362.   NOTES    : 
  363.  
  364.   RETURNS  : 
  365.   UPDATE   : 
  366. ******************************************************************************/
  367.  
  368. static krui_err  krio_fmtShapeing(int choose_me)
  369. {
  370.   static char   *formats[] = {
  371.                 /*  0   */   "site name",
  372.                 /*  1   */   "sites",
  373.                 /*  2   */   "unitName",
  374.                 /*  3   */   "typeName",
  375.                 /*  4   */   "name",
  376.                 /*  5   */   "site function",
  377.                 /*  6   */   "act func",
  378.                 /*  7   */   "out func",
  379.                 /*  8   */   "no.",
  380.                 /*  9   */   "target",
  381.                 /*  10  */   "act",
  382.                 /*  11  */   "bias",
  383.                 /*  12  */   "position",
  384.                 /*  13  */   "site",
  385.                 /*  14  */   " source:weight",
  386.                 /*  15  */   "subnet",
  387.                 /*  16  */   "layer",
  388.                 /*  17  */   " unitNo."
  389.                              };
  390.  
  391.   char  fmt [ MAX_LIN_LEN ],
  392.         aux [ MAX_LIN_LEN ];
  393.  
  394.   int    len, len1, act_len, out_len;
  395.  
  396.  
  397.   switch( choose_me )
  398.     {
  399.     case  SITE_DEF:
  400.         if (site_name_len + site_func_len + 5 > MAX_LIN_LEN)
  401.           return( KRERR_SAVE_LINE_LEN );
  402.         len = Max( site_name_len, strlen( formats[ 0 ] ) );
  403.         sprintf( aux, "%d", len );
  404.     mstrcpy( fmt_shape1, " %-", aux, "s | %s\n", (char *) 0 );
  405.  
  406.     mstrcpy( fmt, " %-", aux, "s | ", (char *) 0 );
  407.     sprintf( fmt_hdr1, fmt, formats[ 0 ] );
  408.     mstrcat( fmt_hdr1, formats[ 5 ], "\n", (char *) 0 );
  409.  
  410.     mstrcpy( fmt_hdr2 ,krio_repchar( '-', len + 2 ), "|", (char *) 0 );
  411.  
  412.     len = Max( site_func_len, strlen( formats[ 6 ] ));
  413.     mstrcat( fmt_hdr2, krio_repchar( '-', len + 2 ), "\n", (char *) 0 );
  414.  
  415.         break;
  416.  
  417.     case  TYPE_DEF:
  418.     if (act_func_len == 0)    act_len = def_act_func_len;
  419.     else  act_len = act_func_len;
  420.     if (out_func_len == 0)    out_len = def_out_func_len;
  421.     else  out_len = out_func_len;
  422.  
  423.     len = act_len + out_len + site_name_len + type_name_len + 11;
  424.     if (len > MAX_LIN_LEN)    return( KRERR_SAVE_LINE_LEN );
  425.  
  426.     len = Max( type_name_len, strlen( formats[ 4 ] ));
  427.     len1 = len + 2;
  428.     sprintf( aux, "%d", len );
  429.     mstrcpy( fmt_shape1, "%-", aux, "s |", (char *) 0 );
  430.     sprintf( fmt_hdr1, fmt_shape1, formats[ 4 ] );
  431.     mstrcpy( fmt_hdr2, krio_repchar( '-', len + 1 ), "|", (char *) 0 );
  432.  
  433.  
  434.     len = Max( act_len, strlen( formats[ 6 ] ) );
  435.         len1 = len1 + len + 3;
  436.         sprintf( aux, "%d", len );
  437.     mstrcpy( fmt, " %-", aux, "s |", (char *) 0 );
  438.         strcat( fmt_shape1, fmt );
  439.         sprintf( aux, fmt, formats[ 6 ] );
  440.     strcat( fmt_hdr1, aux );
  441.     mstrcat( fmt_hdr2, krio_repchar( '-', len + 2 ), "|", (char *) 0 );
  442.  
  443.     len = Max( out_len, strlen( formats[ 7 ] ) );
  444.         len1 = len1 + len + 3;
  445.         sprintf( aux, "%d", len );
  446.     mstrcpy( fmt, " %-", aux, "s |", (char *) 0 );
  447.     strcat( fmt_shape1, fmt );
  448.  
  449.         sprintf( aux, fmt, formats[ 7 ] );
  450.     mstrcat( fmt_hdr1, aux, formats[1], "\n", (char *) 0 );
  451.     mstrcat( fmt_hdr2, krio_repchar( '-', len + 2 ), "|", (char *) 0 );
  452.     mstrcpy( fmt_blank, ",\n", krio_repchar( ' ', len1 ), (char *) 0 );
  453.  
  454.         len = Max( site_name_len, strlen( formats[ 1 ] ) );
  455.     mstrcat( fmt_hdr2, krio_repchar( '-', len + 2 ), "\n", (char *) 0 );
  456.  
  457.         break;
  458.  
  459.     case  DEFAULT_DEF:
  460.         len = Max( 8, strlen( formats[ 10 ] ) );
  461.         len1 = len + 2;
  462.     if (len1 > MAX_LIN_LEN)  return( KRERR_SAVE_LINE_LEN );
  463.         strcpy( fmt_shape1, "%8.5f |" );
  464.  
  465.         sprintf( aux, "%d", len );
  466.     mstrcpy( fmt, "%-", aux, "s |", (char *) 0 );
  467.     sprintf( fmt_hdr1, fmt, formats[ 10 ] );
  468.  
  469.     mstrcpy( fmt_hdr2, krio_repchar( '-', len + 1 ), "|", (char *) 0 );
  470.  
  471.         len = Max( 8, strlen( formats[ 11 ] ) );
  472.         len1 = len1 + len + 3;
  473.     if (len1 > MAX_LIN_LEN)  return( KRERR_SAVE_LINE_LEN );
  474.         strcat( fmt_shape1, " %8.5f |" );
  475.  
  476.         sprintf( aux, "%d", len );
  477.     mstrcpy( fmt, " %-", aux, "s |", (char *) 0 );
  478.         sprintf( aux, fmt, formats[ 11 ] );
  479.     strcat( fmt_hdr1, aux );
  480.  
  481.     mstrcat( fmt_hdr2, krio_repchar( '-', len + 2 ), "|", (char *) 0 );
  482.  
  483.         len1 = len1 + 5;
  484.     if (len1 > MAX_LIN_LEN)  return( KRERR_SAVE_LINE_LEN );
  485.         strcat( fmt_shape1, " %s  |" );
  486.         strcat( fmt_hdr1, " st |" );
  487.     strcat( fmt_hdr2, "----|" );
  488.  
  489.         len = Max( subnet_no_len, strlen( formats[ 15 ] ) );
  490.     len1 += len + 3;
  491.     if (len1 > MAX_LIN_LEN)  return( KRERR_SAVE_LINE_LEN );
  492.         sprintf( aux, "%d", len );
  493.     mstrcat( fmt_shape1, " %", aux, "d |", (char *) 0 );
  494.  
  495.     mstrcpy( fmt, " %-", aux, "s |", (char *) 0 );
  496.         sprintf( aux, fmt, formats[ 15 ] );
  497.     strcat( fmt_hdr1, aux );
  498.  
  499.     mstrcat( fmt_hdr2, krio_repchar( '-', len + 2 ), "|", (char *) 0 );
  500.  
  501.         len = Max( layer_no_len, strlen( formats[ 16 ] ) );
  502.     len1 += len + 3;
  503.     if (len1 > MAX_LIN_LEN)  return( KRERR_SAVE_LINE_LEN );
  504.         sprintf( aux, "%d", len );
  505.     mstrcat( fmt_shape1, " %", aux, "d |", (char *) 0 );
  506.  
  507.     mstrcpy( fmt, " %-", aux, "s |", (char *) 0 );
  508.         sprintf( aux, fmt, formats[ 16 ] );
  509.     strcat( fmt_hdr1, aux );
  510.  
  511.     mstrcat( fmt_hdr2, krio_repchar( '-', len + 2 ), "|", (char *) 0 );
  512.  
  513.     len = Max( def_act_func_len, strlen( formats[ 6 ] ) );
  514.     len1 += len + 3;
  515.     if (len1 > MAX_LIN_LEN)  return( KRERR_SAVE_LINE_LEN );
  516.         sprintf( aux, "%d", len );
  517.     mstrcpy( fmt, " %-", aux, "s | ", (char *) 0 );
  518.         strcat( fmt_shape1, fmt );
  519.         sprintf( aux, fmt, formats[ 6 ] );
  520.     mstrcat( fmt_hdr1, aux, formats[7], "\n", (char *) 0 );
  521.  
  522.     mstrcat( fmt_hdr2, krio_repchar( '-', len + 2 ), "|", (char *) 0 );
  523.  
  524.  
  525.     len = Max( def_out_func_len, strlen( formats[ 7 ] ) );
  526.     len1 += len + 1;
  527.     if (len1 > MAX_LIN_LEN)  return( KRERR_SAVE_LINE_LEN );
  528.         sprintf( aux, "%d", len );
  529.     mstrcat( fmt_shape1, "%-", aux, "s \n", (char *) 0 );
  530.  
  531.     mstrcat( fmt_hdr2, krio_repchar( '-', len + 1 ), "\n", (char *) 0 );
  532.  
  533.         break;
  534.  
  535.     case  UNIT_DEF:
  536.         len = Max( unit_no_len, strlen( formats[ 8 ] ) );
  537.     len1 = len + 2;
  538.     if (len1 > MAX_LIN_LEN)  return( KRERR_SAVE_LINE_LEN );
  539.  
  540.     sprintf( aux, "%d", len );
  541.     mstrcpy( fmt_shape1, "%", aux, "d |", (char *) 0 );
  542.  
  543.     mstrcpy( fmt, "%", aux, "s |", (char *) 0 );
  544.     sprintf( fmt_hdr1, fmt, formats[ 8 ] );
  545.  
  546.     mstrcpy( fmt_hdr2, krio_repchar( '-', len + 1 ), "|", (char *) 0);
  547.  
  548.  
  549.         len = Max( type_name_len, strlen( formats[ 3 ] ) );
  550.     len1 += len + 3;
  551.     if (len1 > MAX_LIN_LEN)  return( KRERR_SAVE_LINE_LEN );
  552.  
  553.     sprintf( aux, "%d", len );
  554.     mstrcpy( fmt, " %-", aux, "s |", (char *) 0 );
  555.     strcat( fmt_shape1, fmt );
  556.  
  557.     sprintf( aux, fmt, formats[ 3 ] );
  558.         strcat( fmt_hdr1, aux );
  559.     mstrcat( fmt_hdr2, krio_repchar( '-', len + 2 ), "|", (char *) 0 );
  560.  
  561.  
  562.         len = Max( unit_name_len, strlen( formats[ 2 ] ) );
  563.     len1 += len + 3;
  564.     if (len1 > MAX_LIN_LEN)  return( KRERR_SAVE_LINE_LEN );
  565.  
  566.     sprintf( aux, "%d", len );
  567.     mstrcpy( fmt, " %-", aux, "s |", (char *) 0 );
  568.     strcat( fmt_shape1, fmt );
  569.  
  570.     sprintf( aux, fmt, formats[ 2 ] );
  571.     strcat( fmt_hdr1, aux );
  572.     mstrcat( fmt_hdr2, krio_repchar( '-', len + 2 ), "|", (char *) 0 );
  573.  
  574.  
  575.         len = Max( 8, strlen( formats[ 10 ] ) );
  576.     len1 += len + 3;
  577.     if (len1 > MAX_LIN_LEN)  return( KRERR_SAVE_LINE_LEN );
  578.  
  579.         strcat( fmt_shape1, " %8.5f |" );
  580.         sprintf( aux, "%d", len );
  581.     mstrcpy( fmt, " %-", aux, "s |", (char *) 0 );
  582.  
  583.         sprintf( aux, fmt, formats[ 10 ] );
  584.         strcat( fmt_hdr1, aux );
  585.     mstrcat( fmt_hdr2, krio_repchar( '-', len + 2 ), "|", (char *) 0 );
  586.  
  587.  
  588.         len = Max( 8, strlen( formats[ 11 ] ) );
  589.         len1 = len1 + len + 3;
  590.     if (len1 > MAX_LIN_LEN)  return( KRERR_SAVE_LINE_LEN );
  591.         strcat( fmt_shape1, " %8.5f |" );
  592.         sprintf( aux, "%d", len );
  593.  
  594.     mstrcpy( fmt, " %-", aux, "s |", (char *) 0 );
  595.  
  596.         sprintf( aux, fmt, formats[ 11 ] );
  597.         strcat( fmt_hdr1, aux );
  598.     mstrcat( fmt_hdr2, krio_repchar( '-', len + 2 ), "|", (char *) 0 );
  599.  
  600.  
  601.     len1 += 5;
  602.     if (len1 > MAX_LIN_LEN)  return( KRERR_SAVE_LINE_LEN );
  603.     strcat( fmt_shape1, " %s  |" );
  604.     strcat( fmt_hdr1, " st |" );
  605.     strcat( fmt_hdr2, "----|" );
  606.  
  607. #ifndef KERNEL3D
  608.         len = Max( pos_no_len * 2 + 1, strlen( formats[ 12 ] ) );
  609. #else
  610.         len = Max( pos_no_len * 3 + 2, strlen( formats[ 12 ] ) );
  611. #endif
  612.     len1 += len + 3;
  613.     if (len1 > MAX_LIN_LEN)  return( KRERR_SAVE_LINE_LEN );
  614.         sprintf( aux, "%d", pos_no_len );
  615.     mstrcpy( fmt, " %", aux, "d,", (char *) 0 );
  616.         strcat( fmt_shape1, fmt );
  617.  
  618.         sprintf( aux, "%d", pos_no_len );
  619.     mstrcpy( fmt, "%", aux, "d", (char *) 0 );
  620.  
  621. #ifdef KERNEL3D
  622.         strcat( fmt_shape1, fmt );
  623.         sprintf( aux, "%d", pos_no_len );
  624.     mstrcpy( fmt, ",%", aux, "d", (char *) 0 );
  625. #endif
  626. #ifndef KERNEL3D
  627.         if ((pos_no_len * 2 + 1) < len)
  628.           strcat( fmt, krio_repchar( ' ', len - (pos_no_len * 2 + 1)) );
  629. #else
  630.         if ((pos_no_len * 3 + 2) < len)
  631.           strcat( fmt, krio_repchar( ' ', len - (pos_no_len * 3 + 2)) );
  632. #endif
  633.  
  634.         strcat( fmt, " |" );
  635.         strcat( fmt_shape1, fmt );
  636.  
  637.         sprintf( aux, "%d", len );
  638.     mstrcpy( fmt, " %-", aux, "s |", (char *) 0 );
  639.  
  640.         sprintf( aux, fmt, formats[ 12 ] );
  641.         strcat( fmt_hdr1, aux );
  642.     mstrcat( fmt_hdr2, krio_repchar( '-', len + 2 ), "|", (char *) 0 );
  643.  
  644.  
  645.         len = Max( act_func_len, strlen( formats[ 6 ] ) );
  646.     len1 += len + 3;
  647.     if (len1 > MAX_LIN_LEN)  return( KRERR_SAVE_LINE_LEN );
  648.     strcpy( fmt_shape2, fmt_shape1 );
  649.     strcat( fmt_shape2, "||" );
  650.         sprintf( aux, "%d", len );
  651.     mstrcpy( fmt, " %-", aux, "s |", (char *) 0 );
  652.     strcat( fmt_shape1, fmt );
  653.  
  654.         sprintf( aux, fmt, formats[ 6 ] );
  655.         strcat( fmt_hdr1, aux );
  656.     mstrcat( fmt_hdr2, krio_repchar( '-', len + 2 ), "|", (char *) 0 );
  657.  
  658.  
  659.         len = Max( out_func_len, strlen( formats[ 7 ] ) );
  660.     len1 += len + 3;
  661.     if (len1 > MAX_LIN_LEN)  return( KRERR_SAVE_LINE_LEN );
  662.         sprintf( aux, "%d", len );
  663.     mstrcpy( fmt, " %-", aux, "s | ", (char *) 0 );
  664.     strcat( fmt_shape1, fmt );
  665.  
  666.         sprintf( aux, fmt, formats[ 7 ] );
  667.     mstrcat( fmt_hdr1, aux, formats[1], "\n", (char *) 0 );
  668.  
  669.     mstrcat( fmt_hdr2, krio_repchar( '-', len + 2 ), "|", (char *) 0 );
  670.     mstrcpy( fmt_blank, ",\n", krio_repchar( ' ', len1 ), (char *) 0 );
  671.  
  672.  
  673.         len = Max( site_name_len, strlen( formats[ 1 ] ) );
  674.     len1 += len + 2;
  675.     if (len1 + len > MAX_LIN_LEN)  return( KRERR_SAVE_LINE_LEN );
  676.     mstrcat( fmt_hdr2, krio_repchar( '-', len + 2 ), "\n", (char *) 0 );
  677.  
  678.         break;
  679.  
  680.     case  CONNECT_DEF:
  681.         sprintf( aux, "%d", unit_no_len );
  682.     mstrcpy( fmt_shape3, " %", aux, "d:%8.5f", (char *) 0 );
  683.  
  684.         len = Max( unit_no_len, strlen( formats[ 9 ] ) );
  685.         len1 = len + 2;
  686.     if (len1 > MAX_LIN_LEN)  return( KRERR_SAVE_LINE_LEN );
  687.         sprintf( aux, "%d", len );
  688.     mstrcpy( fmt_shape1, "%", aux, "d |", (char *) 0 );
  689.  
  690.     mstrcpy( fmt, "%", aux, "s |", (char *) 0 );
  691.     sprintf( fmt_hdr1, fmt, formats[ 9 ] );
  692.     mstrcpy( fmt_hdr2, krio_repchar( '-', len + 1 ), "|", (char *) 0 );
  693.         strcpy( fmt_shape2, krio_repchar( ' ', len1 ) );
  694.  
  695.         len = Max( site_name_len, strlen( formats[ 13 ] ) );
  696.         len1 = len1 + len + 3;
  697.     if (len1 > MAX_LIN_LEN)  return( KRERR_SAVE_LINE_LEN );
  698.         sprintf( aux, "%d", len );
  699.  
  700.  
  701.     mstrcpy( fmt, " %-", aux, "s |", (char *) 0 );
  702.         strcat( fmt_shape1, fmt );
  703.         strcat( fmt_shape2, fmt );
  704.         sprintf( aux, fmt, formats[ 13 ] );
  705.     mstrcat( fmt_hdr1, aux, formats[14], "\n", (char *) 0 );
  706.  
  707.     mstrcat( fmt_hdr2, krio_repchar( '-', len + 2 ), "|", (char *) 0 );
  708.     mstrcpy( fmt_blank, "\n", krio_repchar( ' ', len1 ), (char *) 0 );
  709.  
  710.     if ((len1 + unit_no_len + 14) > MAX_LIN_LEN)  
  711.         return( KRERR_SAVE_LINE_LEN );
  712.         max_connects_per_line = (BEST_LINE_LEN - len1) / (unit_no_len + 11);
  713.     mstrcat( fmt_hdr2,
  714.          krio_repchar( '-', 
  715.                   (unit_no_len + 11) * max_connects_per_line ),
  716.         "\n", (char *) 0 );
  717.  
  718.         break;
  719.  
  720.       case  SUBNET_DEF:
  721.         len = Max( subnet_no_len, strlen( formats[ 15 ] ) );
  722.     len1 = len + 1;
  723.         sprintf( aux, "%d", len );
  724.     mstrcpy( fmt_shape1, "\n%", aux, "d |", (char *) 0 );
  725.  
  726.         sprintf( aux, "%d", len );
  727.     mstrcpy( fmt, "%", aux, "s |", (char *) 0 );
  728.         sprintf( fmt_hdr1, fmt, formats[ 15 ] );
  729.         strcat( fmt_hdr1, formats[17] );
  730.     mstrcpy( fmt_hdr2, "\n", krio_repchar( '-', len1 ), "|", (char *) 0 );
  731.     mstrcpy( fmt_blank, "\n", krio_repchar( ' ', len1 + 1 ), (char *) 0 );
  732.  
  733.         sprintf( aux, "%d", unit_no_len );
  734.     mstrcat( fmt_shape1, " %", aux, "d", (char *) 0 );
  735.     mstrcpy( fmt_shape2, " %", aux, "d", (char *) 0 );
  736.  
  737.         max_subnets_per_line = (BEST_LINE_LEN - len1 - 1) / (unit_no_len + 2);
  738.         strcat( fmt_hdr2, krio_repchar( '-', (unit_no_len + 2) 
  739.                              * max_subnets_per_line ) );
  740.  
  741.         break;
  742.  
  743.       case  LAYER_DEF:
  744.         len = Max( layer_no_len, strlen( formats[ 16 ] ) );
  745.     len1 = len + 1;
  746.         sprintf( aux, "%d", len );
  747.     mstrcpy( fmt_shape1, "\n%", aux, "d |", (char *) 0 );
  748.  
  749.     mstrcpy( fmt, "%", aux, "s |", (char *) 0 );
  750.         sprintf( fmt_hdr1, fmt, formats[ 16 ] );
  751.         strcat( fmt_hdr1, formats[17] );
  752.  
  753.     mstrcpy( fmt_hdr2, "\n", krio_repchar( '-', len1 ), "|", (char *) 0 );
  754.     mstrcpy( fmt_blank, "\n", krio_repchar( ' ', len1 + 1 ), (char *) 0 );
  755.  
  756.         sprintf( aux, "%d", unit_no_len );
  757.     mstrcat( fmt_shape1, " %", aux, "d", (char *) 0 );
  758.     mstrcpy( fmt_shape2, " %", aux, "d", (char *) 0 );
  759.  
  760.         max_layers_per_line = (BEST_LINE_LEN - len1 - 1) / (unit_no_len + 2);
  761.         strcat( fmt_hdr2, krio_repchar( '-', (unit_no_len + 2) 
  762.                              * max_layers_per_line ) );
  763.  
  764.         break;
  765.   }
  766.  
  767.   return( 0 );
  768. }
  769.  
  770.  
  771.  
  772. /*****************************************************************************
  773.   FUNCTION : krio_writeSiteDefinitions 
  774.  
  775.   PURPOSE  : 
  776.   NOTES    : 
  777.  
  778.   RETURNS  : 
  779.   UPDATE   : 
  780. ******************************************************************************/
  781.  
  782. static krui_err  krio_writeSiteDefinitions(void)
  783. {
  784.   int   err;
  785.   char  *site_name,
  786.         *site_func;
  787.  
  788.  
  789.   if ( !krui_getFirstSiteTableEntry( &site_name, &site_func ) )
  790.     return( 0 );
  791.  
  792.   err = krio_fmtShapeing( SITE_DEF );
  793.   retchk( err );
  794.  
  795.   err = fprintf( file_out, "\n\n%s :\n\n", title[8] );
  796.   retchk( err );
  797.   err = fprintf( file_out, fmt_hdr1 );
  798.   retchk( err );
  799.   err = fprintf( file_out, fmt_hdr2 );
  800.   retchk( err );
  801.  
  802.   do
  803.     {
  804.     err = fprintf( file_out, fmt_shape1,
  805.                    site_name, site_func );
  806.     retchk( err );
  807.   }
  808.   while (krui_getNextSiteTableEntry( &site_name, &site_func ) );
  809.  
  810.   err = fprintf( file_out, fmt_hdr2 );
  811.   retchk( err );
  812.   return( 0 );
  813. }
  814.  
  815.  
  816.  
  817. /*****************************************************************************
  818.   FUNCTION : krio_writeTypeDefinitions 
  819.  
  820.   PURPOSE  : 
  821.   NOTES    : 
  822.  
  823.   RETURNS  : 
  824.   UPDATE   : 
  825. ******************************************************************************/
  826.  
  827. static krui_err  krio_writeTypeDefinitions(void)
  828. {
  829.   int   err;
  830.   bool  second;
  831.  
  832.  
  833.   if ( !krui_setFirstFTypeEntry() )
  834.     return( 0 );
  835.  
  836.   err = krio_fmtShapeing( TYPE_DEF );
  837.   retchk( err );
  838.  
  839.   err = fprintf( file_out, "\n\n%s :\n\n", title[9] );
  840.   retchk( err );
  841.   err = fprintf( file_out, fmt_hdr1 );
  842.   retchk( err );
  843.   err = fprintf( file_out, fmt_hdr2 );
  844.   retchk( err );
  845.  
  846.   do  {
  847.     err = fprintf( file_out, fmt_shape1,
  848.                    krui_getFTypeName(),
  849.                    krui_getFTypeActFuncName(), krui_getFTypeOutFuncName() );
  850.     retchk( err );
  851.  
  852.     if ( krui_setFirstFTypeSite() )  {
  853.       second = FALSE;
  854.       do  {
  855.         if (second)  {
  856.       err = fprintf( file_out, fmt_blank );
  857.           retchk( err );
  858.     }
  859.  
  860.     err = fprintf( file_out, " %-s", krui_getFTypeSiteName() );
  861.         retchk( err );
  862.         second = TRUE;
  863.       }
  864.       while ( krui_setNextFTypeSite() );
  865.     }
  866.  
  867.     err = fprintf( file_out, "\n" );
  868.     retchk( err );
  869.   }
  870.   while (krui_setNextFTypeEntry() );
  871.  
  872.   err = fprintf( file_out, fmt_hdr2 );
  873.   if (err <= 0)  return( err );
  874.  
  875.   return( 0 );
  876. }
  877.  
  878. /*****************************************************************************
  879.   FUNCTION : getTType 
  880.  
  881.   PURPOSE  : 
  882.   NOTES    : 
  883.  
  884.   RETURNS  : 
  885.   UPDATE   : 
  886. ******************************************************************************/
  887.  
  888. static char  *getTType(int st)
  889. {
  890.   static char   *ttype[] = { "-", "i", "o", "d", "h", "s" ,
  891.                              "si", "so", "sh", "sd"}; 
  892.  
  893.   switch ( st )  {
  894.     case  INPUT:
  895.       return( ttype[1] );
  896.     case  OUTPUT:
  897.       return( ttype[2] );
  898.     case  DUAL:
  899.       return( ttype[3] );
  900.     case  HIDDEN:
  901.       return( ttype[4] );
  902.     case  SPECIAL:
  903.       return( ttype[5] );
  904.     case  SPECIAL_I:      
  905.       return( ttype[6] ); 
  906.     case  SPECIAL_O:      
  907.       return( ttype[7] ); 
  908.     case  SPECIAL_H:      
  909.       return( ttype[8] ); 
  910.     case  SPECIAL_D:      
  911.       return( ttype[9] ); 
  912.     default:
  913.       return( ttype[0] );
  914.   }
  915. }
  916.  
  917.  
  918. /*****************************************************************************
  919.   FUNCTION : krio_writeDefaultDefinitions 
  920.  
  921.   PURPOSE  : 
  922.   NOTES    : 
  923.  
  924.   RETURNS  : 
  925.   UPDATE   : 
  926. ******************************************************************************/
  927.  
  928. static krui_err  krio_writeDefaultDefinitions(void)
  929. {
  930.   int   err;
  931.   FlintType  act, bias;
  932.   int   st, subnet_no, layer_no;
  933.   char  *act_func,  *out_func;
  934.  
  935.  
  936.   err = krio_fmtShapeing( DEFAULT_DEF );
  937.   retchk( err );
  938.  
  939.   err = fprintf( file_out, "\n\n%s :\n\n", title[13] );
  940.   retchk( err );
  941.   err = fprintf( file_out, fmt_hdr1 );
  942.   retchk( err );
  943.   err = fprintf( file_out, fmt_hdr2 );
  944.   retchk( err );
  945.  
  946.   krui_getUnitDefaults( &act, &bias, &st, &subnet_no, &layer_no,
  947.                         &act_func, &out_func );
  948.  
  949.   if ((act_func != NULL) && (out_func != NULL))  {
  950.     err = fprintf( file_out, fmt_shape1, act, bias, getTType( st ),
  951.                    subnet_no, layer_no, act_func, out_func );
  952.   }
  953.   else  {
  954.     err = fprintf( file_out, fmt_shape1, act, bias, getTType( st ),
  955.                    subnet_no, layer_no, " ", " " );
  956.   }
  957.  
  958.   retchk( err );
  959.  
  960.   err = fprintf( file_out, fmt_hdr2 );
  961.   retchk( err );
  962.  
  963.   return( 0 );
  964. }
  965.  
  966.  
  967. /*****************************************************************************
  968.   FUNCTION : krio_writeUnitDefinitions 
  969.  
  970.   PURPOSE  : 
  971.   NOTES    : 
  972.  
  973.   RETURNS  : 
  974.   UPDATE   : 
  975. ******************************************************************************/
  976.  
  977. static krui_err  krio_writeUnitDefinitions(void)
  978. {
  979.   static char   *blank = "\0";
  980.  
  981.   struct  PosType   pos;
  982.  
  983.   char  *u_type,
  984.         *u_name,
  985.         *act_func,
  986.         *act_func_def,
  987.         *out_func_def,
  988.         *out_func;
  989.  
  990.   bool  no_Ftype, second,
  991.         writeUnitActFuncName, writeUnitOutFuncName;
  992.   int   err,
  993.         unit_no,
  994.         u_no,
  995.         st_def, subnet_no, layer_no;
  996.  
  997.   FlintType  act_def, bias_def;
  998.  
  999.  
  1000.  
  1001.   if (NoOfUnits <= 0)  return( KRERR_NO_ERROR );
  1002.  
  1003.   err = krio_fmtShapeing( UNIT_DEF );
  1004.   retchk( err );
  1005.  
  1006.   err = fprintf( file_out, "\n\n%s :\n\n", title[10] );
  1007.   retchk( err );
  1008.   err = fprintf( file_out, fmt_hdr1 );
  1009.   retchk( err );
  1010.   err = fprintf( file_out, fmt_hdr2 );
  1011.   retchk( err );
  1012.  
  1013.   krui_getUnitDefaults( &act_def, &bias_def, &st_def, &subnet_no, &layer_no,
  1014.                         &act_func_def, &out_func_def );
  1015.  
  1016.   unit_no = krui_getFirstUnit();
  1017.   u_no = 1;
  1018.  
  1019.   do  {
  1020.     krui_getUnitPosition( unit_no, &pos );
  1021.  
  1022.     if ( (u_name = krui_getUnitName( unit_no )) == NULL)
  1023.       u_name = blank;
  1024.  
  1025.     if ( (u_type = krui_getUnitFTypeName( unit_no )) == NULL)
  1026.       {  /*  no ftype  */
  1027.       no_Ftype = TRUE;
  1028.  
  1029.       act_func = krui_getUnitActFuncName( unit_no );
  1030.       out_func = krui_getUnitOutFuncName( unit_no );
  1031.  
  1032.       writeUnitActFuncName = strcmp( act_func, act_func_def) != 0;
  1033.       writeUnitOutFuncName = strcmp( out_func, out_func_def) != 0;
  1034.  
  1035.       if (!writeUnitActFuncName && !writeUnitOutFuncName)  {
  1036. #ifndef KERNEL3D
  1037.     err = fprintf( file_out, fmt_shape2,
  1038.            u_no, blank, u_name,
  1039.                    krui_getUnitActivation( unit_no ),
  1040.                    krui_getUnitBias( unit_no ),
  1041.                    getTType( krui_getUnitTType( unit_no ) ),
  1042.            pos.x, pos.y );
  1043. #else
  1044.     err = fprintf( file_out, fmt_shape2,
  1045.            u_no, blank, u_name,
  1046.                    krui_getUnitActivation( unit_no ),
  1047.                    krui_getUnitBias( unit_no ),
  1048.                    getTType( krui_getUnitTType( unit_no ) ),
  1049.            pos.x, pos.y, pos.z );
  1050. #endif
  1051.     }
  1052.       else  {
  1053.     if (!writeUnitActFuncName)  act_func = blank;
  1054.     if (!writeUnitOutFuncName)  out_func = blank;
  1055.  
  1056. #ifndef KERNEL3D
  1057.     err = fprintf( file_out, fmt_shape1,
  1058.            u_no, blank, u_name,
  1059.                    krui_getUnitActivation( unit_no ),
  1060.                    krui_getUnitBias( unit_no ),
  1061.                    getTType( krui_getUnitTType( unit_no ) ),
  1062.                    pos.x, pos.y, act_func, out_func );
  1063. #else
  1064.     err = fprintf( file_out, fmt_shape1,
  1065.            u_no, blank, u_name,
  1066.                    krui_getUnitActivation( unit_no ),
  1067.                    krui_getUnitBias( unit_no ),
  1068.                    getTType( krui_getUnitTType( unit_no ) ),
  1069.                    pos.x, pos.y, pos.z, act_func, out_func );
  1070. #endif
  1071.       }
  1072.     }
  1073.     else  {
  1074. #ifndef KERNEL3D
  1075.     err = fprintf( file_out, fmt_shape2,
  1076.                    u_no, u_type, u_name,
  1077.                    krui_getUnitActivation( unit_no ),
  1078.                    krui_getUnitBias( unit_no ),
  1079.                    getTType( krui_getUnitTType( unit_no ) ),
  1080.            pos.x, pos.y );
  1081. #else
  1082.     err = fprintf( file_out, fmt_shape2,
  1083.                    u_no, u_type, u_name,
  1084.                    krui_getUnitActivation( unit_no ),
  1085.                    krui_getUnitBias( unit_no ),
  1086.                    getTType( krui_getUnitTType( unit_no ) ),
  1087.            pos.x, pos.y, pos.z );
  1088. #endif
  1089.  
  1090.       no_Ftype = FALSE;
  1091.     }
  1092.  
  1093.  
  1094.     retchk( err );
  1095.  
  1096.     if ( no_Ftype )  {
  1097.       if ( krui_setFirstSite() )  {
  1098.         second = FALSE;
  1099.         do  {
  1100.           if (second)  {
  1101.         err = fprintf( file_out, fmt_blank );
  1102.         retchk( err );
  1103.       }
  1104.  
  1105.       err = fprintf( file_out, " %-s", krui_getSiteName() );
  1106.           retchk( err );
  1107.           second = TRUE;
  1108.     }
  1109.         while ( krui_setNextSite() );
  1110.       }
  1111.     }
  1112.  
  1113.     err = fprintf( file_out, "\n" );
  1114.     retchk( err );
  1115.     u_no++;
  1116.   }
  1117.   while ( (unit_no = krui_getNextUnit() ) > 0);
  1118.  
  1119.   err = fprintf( file_out, fmt_hdr2 );
  1120.   retchk( err );
  1121.  
  1122.   return( KRERR_NO_ERROR );
  1123. }
  1124.  
  1125.  
  1126. /*****************************************************************************
  1127.   FUNCTION : krio_writeTimeDelayDefs
  1128.  
  1129.   PURPOSE  : 
  1130.   NOTES    : 
  1131.  
  1132.   RETURNS  : 
  1133.   UPDATE   : 
  1134. ******************************************************************************/
  1135. static krui_err    krio_writeTimeDelayDefs(void)
  1136. {
  1137.  
  1138.   struct Unit  *unit_ptr;
  1139.  
  1140.   int   err,
  1141.         unit_no,
  1142.         u_no,
  1143.         lln,
  1144.         lun,
  1145.         toff,
  1146.         soff,
  1147.         conn_type;
  1148.  
  1149.   if (NoOfUnits <= 0)
  1150.     return( 0 );
  1151.  
  1152.  
  1153.   if ((strcmp (krui_getLearnFunc(), "TimeDelayBackprop") == 0) || 
  1154.       (strcmp (krui_getLearnFunc(), "TDBP_McClelland") == 0)) {
  1155.   
  1156.      err = fprintf( file_out, "\n\n%s :\n\n", title[18] ); 
  1157.      retchk( err );
  1158.      err = fprintf (file_out, "%s\n", headers[8]);
  1159.      retchk (err);
  1160.      err = fprintf (file_out, "-----|-----|-----|------|------|-------\n");
  1161.      retchk (err);
  1162.  
  1163.      unit_no = krui_getFirstUnit ();
  1164.      u_no = 1;
  1165.  
  1166.      do {
  1167.  
  1168.        unit_ptr = kr_getUnitPtr (unit_no);
  1169.  
  1170.        lln = unit_ptr->lln;
  1171.        lun = unit_ptr->lun;
  1172.        toff = unit_ptr->TD.target_offset;
  1173.        soff = unit_ptr->TD.source_offset;
  1174.        conn_type = unit_ptr->TD.td_connect_typ;
  1175.     
  1176.        err = fprintf (file_out, "%4d |%4d |%4d |%5d |%5d |%6d\n", 
  1177.               u_no, lln, lun, toff, soff, conn_type);
  1178.        retchk (err);
  1179.     
  1180.        unit_no = krui_getNextUnit ();
  1181.        u_no++;
  1182.  
  1183.      } while (unit_no != 0);
  1184.  
  1185.      err = fprintf(file_out, "-----|-----|-----|------|------|-------\n");
  1186.      retchk (err);
  1187.  
  1188.    }
  1189.   
  1190.   return (KRERR_NO_ERROR);
  1191. }
  1192.  
  1193.  
  1194.  
  1195.  
  1196. /*****************************************************************************
  1197.   FUNCTION : krio_writeSourcesAndWeights  
  1198.  
  1199.   PURPOSE  : write link weights
  1200.   NOTES    : 
  1201.  
  1202.   RETURNS  : 
  1203.   UPDATE   : 
  1204. ******************************************************************************/
  1205. static krui_err  krio_writeSourcesAndWeights(void)
  1206. {
  1207.   bool  second;
  1208.   int   i, err,
  1209.         source_unit;
  1210.  
  1211.   FlintType     weight;
  1212.  
  1213.  
  1214.   i = 0;
  1215.   source_unit = krui_getFirstPredUnit( &weight );
  1216.   second = FALSE;
  1217.  
  1218.   do  {
  1219.     if (second)  {
  1220.       err = fprintf( file_out, "," );
  1221.       retchk( err );
  1222.     }
  1223.  
  1224.     if (++i > max_connects_per_line)  {
  1225.       i = 1;
  1226.       err = fprintf( file_out, fmt_blank );
  1227.       retchk( err );
  1228.     }
  1229.  
  1230.     err = fprintf( file_out, fmt_shape3, source_unit, weight );
  1231.     retchk( err );
  1232.  
  1233.     second = TRUE;
  1234.   }
  1235.   while ( (source_unit = krui_getNextPredUnit( &weight )) > 0);
  1236.  
  1237.   err = fprintf( file_out, "\n" );
  1238.   retchk( err );
  1239.  
  1240.   return( KRERR_NO_ERROR );
  1241. }
  1242.  
  1243. /*****************************************************************************
  1244.   FUNCTION : krio_writeConnectionDefs 
  1245.  
  1246.   PURPOSE  : 
  1247.   NOTES    : 
  1248.  
  1249.   RETURNS  : 
  1250.   UPDATE   : 
  1251. ******************************************************************************/
  1252.  
  1253. static krui_err  krio_writeConnectionDefs(void)
  1254. {
  1255.   bool  second;
  1256.   int   target_unit, unit_no,
  1257.         err;
  1258.  
  1259.   FlintType  weight;
  1260.  
  1261.  
  1262.   if (NoOfLinks == 0)  return( 0 );
  1263.  
  1264.   err = krio_fmtShapeing( CONNECT_DEF );
  1265.   retchk( err );
  1266.  
  1267.   err = fprintf( file_out, "\n\n%s :\n\n", title[11] );
  1268.   retchk( err );
  1269.   err = fprintf( file_out, fmt_hdr1 );
  1270.   retchk( err );
  1271.   err = fprintf( file_out, fmt_hdr2 );
  1272.   retchk( err );
  1273.  
  1274.   unit_no = krui_getFirstUnit();
  1275.   target_unit = 1;
  1276.  
  1277.   do  {
  1278.     switch (krui_getUnitInputType( unit_no ))  {
  1279.       case  DIRECT_LINKS:
  1280.     err = fprintf( file_out, fmt_shape1, target_unit, " ");
  1281.         retchk( err );
  1282.     err = krio_writeSourcesAndWeights();
  1283.         retchk( err );
  1284.  
  1285.         break;
  1286.  
  1287.       case  SITES:
  1288.         krui_setFirstSite();
  1289.         second = FALSE;
  1290.  
  1291.         do  {
  1292.           if (krui_getFirstPredUnit( &weight ) > 0)  {
  1293.             if (second)  {
  1294.           err = fprintf( file_out, fmt_shape2, krui_getSiteName() );
  1295.               retchk( err );
  1296.         }
  1297.             else  {
  1298.           err = fprintf( file_out, fmt_shape1, target_unit, 
  1299.                 krui_getSiteName() );
  1300.               retchk( err );
  1301.         }
  1302.  
  1303.         err = krio_writeSourcesAndWeights();
  1304.             retchk( err );
  1305.  
  1306.             second = TRUE;
  1307.       }
  1308.     }
  1309.         while ( krui_setNextSite() );
  1310.  
  1311.         break;
  1312.     }
  1313.  
  1314.     target_unit++;
  1315.   }
  1316.   while ( (unit_no = krui_getNextUnit()) > 0 );
  1317.  
  1318.   err = fprintf( file_out, fmt_hdr2 );
  1319.   retchk( err );
  1320.   return( KRERR_NO_ERROR );
  1321. }
  1322.  
  1323.  
  1324. /*****************************************************************************
  1325.   FUNCTION : krio_writeSubnetDefs 
  1326.  
  1327.   PURPOSE  : 
  1328.   NOTES    : 
  1329.  
  1330.   RETURNS  : 
  1331.   UPDATE   : 
  1332. ******************************************************************************/
  1333. static krui_err  krio_writeSubnetDefs(void)
  1334. {
  1335.   struct Unit   *unit_ptr,
  1336.                 *unit_ptr2;
  1337.   int    i,  k, elem_no, err, dummy2, def_subnet_no;
  1338.   short  subnet_no;
  1339.   FlintType  dummy1;
  1340.   char    *dummy3;
  1341.  
  1342.  
  1343.   if (!is_subnet_info)  return( 0 );
  1344.  
  1345.   err = krio_fmtShapeing( SUBNET_DEF );
  1346.   retchk( err );
  1347.  
  1348.   err = fprintf( file_out, "\n\n%s :\n\n", title[12] );
  1349.   retchk( err );
  1350.   err = fprintf( file_out, fmt_hdr1 );
  1351.   retchk( err );
  1352.   err = fprintf( file_out, fmt_hdr2 );
  1353.   retchk( err );
  1354.  
  1355.   /*  get default subnet number  */
  1356.   krui_getUnitDefaults( &dummy1, &dummy1, &dummy2, &def_subnet_no, &dummy2,
  1357.             &dummy3, &dummy3 );
  1358.  
  1359.   /*  clear refresh flags  */
  1360.   FOR_ALL_UNITS( unit_ptr )
  1361.     unit_ptr->flags &= ~UFLAG_REFRESH;
  1362.  
  1363.   for (i = MinUnitNo, unit_ptr = unit_array + MinUnitNo; 
  1364.        i <= MaxUnitNo; 
  1365.        i++, unit_ptr++)
  1366.       if (!UNIT_REFRESHED( unit_ptr ) && UNIT_IN_USE( unit_ptr ))
  1367.       {                /*  unit is in use and 'fresh' */
  1368.       subnet_no = unit_ptr->subnet_no;
  1369.       if (subnet_no == def_subnet_no)
  1370.           continue;
  1371.  
  1372.       err = fprintf( file_out, fmt_shape1, subnet_no, i);
  1373.       retchk( err );
  1374.       elem_no = 0;
  1375.  
  1376.       for (k = i + 1, unit_ptr2 = unit_ptr + 1;
  1377.            k <= MaxUnitNo;
  1378.            k++, unit_ptr2++ )
  1379.       {
  1380.           if (!UNIT_REFRESHED( unit_ptr ) && UNIT_IN_USE( unit_ptr ))
  1381.           {            /*  unit is in use and 'fresh' */
  1382.           if (unit_ptr2->subnet_no == subnet_no)  {
  1383.               unit_ptr2->flags |= UFLAG_REFRESH;
  1384.  
  1385.               err = fprintf( file_out, "," );
  1386.               retchk( err );
  1387.  
  1388.               if ( (++elem_no % max_subnets_per_line) == 0)  {
  1389.               err = fprintf( file_out, fmt_blank );
  1390.               retchk( err );
  1391.               }
  1392.  
  1393.               err = fprintf( file_out, fmt_shape2,  k);
  1394.               retchk( err );
  1395.           }
  1396.           }
  1397.       }
  1398.       }
  1399.  
  1400.   err = fprintf( file_out, fmt_hdr2 );
  1401.   retchk( err );
  1402.   err = fprintf( file_out, "\n" );
  1403.   retchk( err );
  1404.  
  1405.   return( KRERR_NO_ERROR );
  1406. }
  1407.  
  1408. /*****************************************************************************
  1409.   FUNCTION : krio_writeLayerDefs 
  1410.  
  1411.   PURPOSE  : 
  1412.   NOTES    : 
  1413.  
  1414.   RETURNS  : 
  1415.   UPDATE   : 
  1416. ******************************************************************************/
  1417.  
  1418. static krui_err  krio_writeLayerDefs(void)
  1419. {
  1420.   struct Unit   *unit_ptr,
  1421.                 *unit_ptr2;
  1422.  
  1423.   int    i,  k, elem_no, err, dummy2, def_layer_no;
  1424.   short  layer_no;
  1425.   FlintType  dummy1;
  1426.   char        *dummy3;
  1427.  
  1428.  
  1429.   if (!is_layer_info)  return( KRERR_NO_ERROR );
  1430.  
  1431.   err = krio_fmtShapeing( LAYER_DEF );
  1432.   retchk( err );
  1433.  
  1434.   err = fprintf( file_out, "\n\n%s :\n\n", title[15] );
  1435.   retchk( err );
  1436.   err = fprintf( file_out, fmt_hdr1 );
  1437.   retchk( err );
  1438.   err = fprintf( file_out, fmt_hdr2 );
  1439.   retchk( err );
  1440.  
  1441.   /*  get default layer number    */
  1442.   krui_getUnitDefaults( &dummy1, &dummy1, &dummy2, &dummy2, &def_layer_no,
  1443.             &dummy3, &dummy3 );
  1444.  
  1445.   /*  clear refresh flags  */
  1446.   FOR_ALL_UNITS( unit_ptr )
  1447.     unit_ptr->flags &= ~UFLAG_REFRESH;
  1448.  
  1449.   for (i = MinUnitNo, unit_ptr = unit_array + MinUnitNo; 
  1450.        i <= MaxUnitNo; 
  1451.        i++, unit_ptr++)
  1452.       if (!UNIT_REFRESHED( unit_ptr ) && UNIT_IN_USE( unit_ptr ))
  1453.       {                /*  unit is in use and 'fresh' */
  1454.       layer_no = (int) unit_ptr->layer_no;
  1455.       if (layer_no == def_layer_no)
  1456.           continue;
  1457.  
  1458.       err = fprintf( file_out, fmt_shape1, layer_no, i);
  1459.       retchk( err );
  1460.       elem_no = 0;
  1461.  
  1462.       for (k = i + 1, unit_ptr2 = unit_ptr + 1;
  1463.            k <= MaxUnitNo;
  1464.            k++, unit_ptr2++ )  {
  1465.           if (!UNIT_REFRESHED( unit_ptr ) && UNIT_IN_USE( unit_ptr ))
  1466.           {            /*  unit is in use and 'fresh' */
  1467.           if ((int) unit_ptr2->layer_no == layer_no)  {
  1468.               unit_ptr2->flags |= UFLAG_REFRESH;
  1469.  
  1470.               err = fprintf( file_out, "," );
  1471.               retchk( err );
  1472.  
  1473.               if ( (++elem_no % max_layers_per_line) == 0)  {
  1474.               err = fprintf( file_out, fmt_blank );
  1475.               retchk( err );
  1476.               }
  1477.  
  1478.               err = fprintf( file_out, fmt_shape2, k);
  1479.               retchk( err );
  1480.           }
  1481.           }
  1482.       }
  1483.       }
  1484.  
  1485.   err = fprintf( file_out, fmt_hdr2 );
  1486.   retchk( err );
  1487.   err = fprintf( file_out, "\n" );
  1488.   retchk( err );
  1489.  
  1490.   return( KRERR_NO_ERROR );
  1491. }
  1492.  
  1493.  
  1494. #ifdef KERNEL3D
  1495.  
  1496. static krui_err  writeXYTransTable(void)
  1497. {
  1498.   int err;
  1499.   int z_index;
  1500.  
  1501.  
  1502.   if (transTableSize > 0)  {
  1503.     err = fprintf( file_out, "\n\n%s :\n\n", title[17]);
  1504.     retchk( err );
  1505.     err = fprintf( file_out, " delta x | delta y |    z    \n");
  1506.     retchk( err );
  1507.     err = fprintf( file_out, "---------|---------|---------\n");
  1508.     retchk( err );
  1509.     for (z_index = 0; z_index < transTableSize; z_index++)  {
  1510.     err = fprintf( file_out, "%8d |", transTable[z_index].x);
  1511.     retchk( err );
  1512.     err = fprintf( file_out, "%8d |", transTable[z_index].y);
  1513.     retchk( err );
  1514.     err = fprintf( file_out, "%8d \n", transTable[z_index].z);
  1515.     retchk( err );
  1516.     }
  1517.  
  1518.     err = fprintf( file_out, "---------|---------|---------\n");
  1519.     retchk( err );
  1520.     err = fprintf( file_out, "\n" );
  1521.     retchk( err );
  1522.   }
  1523.  
  1524.   return( KRERR_NO_ERROR );
  1525. }
  1526.  
  1527.  
  1528. #endif
  1529.  
  1530. /*****************************************************************************
  1531.   FUNCTION : krio_saveNet  
  1532.  
  1533.   PURPOSE  : write complete network to disk
  1534.   NOTES    : 
  1535.  
  1536.   RETURNS  : 
  1537.   UPDATE   : 
  1538. ******************************************************************************/
  1539. krui_err  krio_saveNet(char *filename, char *netname)
  1540. {
  1541.   int  err;
  1542.  
  1543.   if (NoOfUnits == 0)  return( KRERR_NO_UNITS );  /*  no units defined    */
  1544.  
  1545.   if ((file_out = fopen( filename, "w" )) == NULL)  {
  1546.     err = KRERR_IO;  /*  file open error  */
  1547.     goto  end;
  1548.   }
  1549.  
  1550.   kr_forceUnitGC();  /*  do unit garbage-collection  */
  1551.  
  1552.   /*  write file header  */
  1553.   err = krio_writeHeader( krio_getIOVersion(), netname );
  1554.  
  1555.   /*  calc. maximum string length of all identifiers  */
  1556.   krio_stringLimits();
  1557.   if (err < 0)    goto end;
  1558.  
  1559.   err = krio_writeSiteDefinitions();
  1560.   if (err < 0)    goto end;
  1561.  
  1562.   err = krio_writeTypeDefinitions();
  1563.   if (err < 0)    goto end;
  1564.  
  1565.   err = krio_writeDefaultDefinitions();
  1566.   if (err < 0)    goto end;
  1567.  
  1568.   err = krio_writeUnitDefinitions();
  1569.   if (err < 0)    goto end;
  1570. /*
  1571.   err = krio_writeTopologicDef();
  1572.   if (err < 0)    goto end;
  1573. */
  1574.   err = krio_writeConnectionDefs();
  1575.   if (err < 0)    goto end;
  1576.  
  1577.   err = krio_writeSubnetDefs();
  1578.   if (err < 0)    goto end;
  1579.   err = krio_writeLayerDefs();
  1580.   if (err < 0)    goto end;
  1581.   err = krio_writeTimeDelayDefs ();
  1582.   if (err < 0)    goto end;
  1583. #ifdef KERNEL3D
  1584.   err = writeXYTransTable();
  1585.   if (err < 0)    goto end;
  1586. #endif
  1587.   err = fclose( file_out );
  1588.  
  1589. end:
  1590.  
  1591.   KernelErrorCode = err;
  1592.  
  1593.   return( KernelErrorCode );
  1594. }
  1595.  
  1596.  
  1597.  
  1598. /*#################################################
  1599.  
  1600. GROUP: Kernel I/O Input Functions
  1601.  
  1602. #################################################*/
  1603. /*****************************************************************************
  1604.   FUNCTION : skipComments 
  1605.  
  1606.   PURPOSE  : 
  1607.   NOTES    : 
  1608.  
  1609.   RETURNS  : 
  1610.   UPDATE   : 
  1611. ******************************************************************************/
  1612.  
  1613. static bool  skipComments(void)
  1614. {
  1615.   register int   c;
  1616.  
  1617.   while (TRUE)  {
  1618.     do  {
  1619.       c = getc( file_in );
  1620.       if (c == '\n')  lineno++;
  1621.     }
  1622.     while ( isspace( c ) );
  1623.  
  1624.     if (c != '#')  break;
  1625.  
  1626.     do
  1627.       c = getc( file_in );
  1628.     while (c != EOF && c != '\n');
  1629.  
  1630.     if (c == '\n')  lineno++;
  1631.   }
  1632.  
  1633.   if (c == EOF)  return( FALSE );
  1634.  
  1635.   ungetc( c, file_in );
  1636.   return( TRUE );
  1637. }
  1638. /*****************************************************************************
  1639.   FUNCTION : skipSpace 
  1640.  
  1641.   PURPOSE  : 
  1642.   NOTES    : 
  1643.  
  1644.   RETURNS  : 
  1645.   UPDATE   : 
  1646. ******************************************************************************/
  1647.  
  1648.  
  1649. static bool  skipSpace(void)
  1650. {
  1651.   register int  c;
  1652.  
  1653.   do  {
  1654.     c = getc( file_in );
  1655.     if (c == '\n')  lineno++;
  1656.   }
  1657.   while ( isspace( c ) );
  1658.  
  1659.   if (c == EOF)  {
  1660.     KernelErrorCode = KRERR_EOF;
  1661.     return( FALSE );
  1662.   }
  1663.  
  1664.   ungetc( c, file_in );
  1665.   return( TRUE );
  1666. }
  1667.  
  1668. /*****************************************************************************
  1669.   FUNCTION : comma  
  1670.  
  1671.   PURPOSE  : 
  1672.   NOTES    : 
  1673.  
  1674.   RETURNS  : 
  1675.   UPDATE   : 
  1676. ******************************************************************************/
  1677.  
  1678. static bool  comma(void)
  1679. {
  1680.   register int  c;
  1681.  
  1682.   do  {
  1683.     c = getc( file_in );
  1684.     if (c == '\n')  lineno++;
  1685.   }
  1686.   while ( isspace( c ) );
  1687.  
  1688.   if (c == EOF)  {  KernelErrorCode = KRERR_EOF;  return( FALSE ); }
  1689.   if (c != ',')  {
  1690.     ungetc( c, file_in );
  1691.     return( FALSE );
  1692.   }
  1693.  
  1694.   do  {
  1695.     c = getc( file_in );
  1696.     if (c == '\n')  lineno++;
  1697.   }
  1698.   while ( isspace( c ) );
  1699.  
  1700.   ungetc( c, file_in );
  1701.   return( TRUE );
  1702. }
  1703.  
  1704.  
  1705. /*****************************************************************************
  1706.   FUNCTION :  get_nl
  1707.  
  1708.   PURPOSE  : 
  1709.   NOTES    : 
  1710.  
  1711.   RETURNS  : 
  1712.   UPDATE   : 
  1713. ******************************************************************************/
  1714.  
  1715. static bool  get_nl(void)
  1716. {
  1717.   register int  c;
  1718.  
  1719.   do  {
  1720.     c = getc( file_in );
  1721.     if (c == '\n')  {
  1722.       lineno++;
  1723.       return( TRUE );
  1724.     }
  1725.   }
  1726.   while ( isspace( c ) );
  1727.  
  1728.   if (c == EOF)  KernelErrorCode = KRERR_EOF;
  1729.   else  ungetc( c, file_in );
  1730.  
  1731.   return( FALSE );
  1732. }
  1733.  
  1734. /*****************************************************************************
  1735.   FUNCTION : get_pipe 
  1736.  
  1737.   PURPOSE  : 
  1738.   NOTES    : 
  1739.  
  1740.   RETURNS  : 
  1741.   UPDATE   : 
  1742. ******************************************************************************/
  1743.  
  1744. static bool  get_pipe(void)
  1745. {
  1746.   register int  c;
  1747.  
  1748.   do  {
  1749.     c = getc( file_in );
  1750.     if (c == '\n')  lineno++;
  1751.   }
  1752.   while ( isspace( c ) );
  1753.  
  1754.   if (c == '|')  return( TRUE );
  1755.  
  1756.   if (c == EOF)  KernelErrorCode = KRERR_EOF;
  1757.   else  ungetc( c, file_in );
  1758.  
  1759.   return( FALSE );
  1760. }
  1761. /*****************************************************************************
  1762.   FUNCTION : skip_pipe  
  1763.  
  1764.   PURPOSE  : 
  1765.   NOTES    : 
  1766.  
  1767.   RETURNS  : 
  1768.   UPDATE   : 
  1769. ******************************************************************************/
  1770.  
  1771. static bool  skip_pipe(void)
  1772. {
  1773.   register int  c;
  1774.  
  1775.   do  {
  1776.     c = getc( file_in );
  1777.     if (c == '\n')  lineno++;
  1778.   }
  1779.   while ( isspace( c ) );
  1780.  
  1781.   if (c == '|')  return( TRUE );
  1782.  
  1783.   if (c == EOF)  KernelErrorCode = KRERR_EOF;
  1784.   else  {
  1785.     ungetc( c, file_in );
  1786.     KernelErrorCode = KRERR_FILE_SYNTAX;
  1787.   }
  1788.  
  1789.   return( FALSE );
  1790. }
  1791.  
  1792. /*****************************************************************************
  1793.   FUNCTION : get_alpha   
  1794.  
  1795.   PURPOSE  : 
  1796.   NOTES    : 
  1797.  
  1798.   RETURNS  : 
  1799.   UPDATE   : 
  1800. ******************************************************************************/
  1801.  
  1802.  
  1803. static bool  get_alpha(void)
  1804. {
  1805.   register int  c;
  1806.  
  1807.   do  {
  1808.     c = getc( file_in );
  1809.     if (c == '\n')  lineno++;
  1810.   }
  1811.   while ( isspace( c ) );
  1812.  
  1813.   if (c == EOF)  KernelErrorCode = KRERR_EOF;
  1814.   else  {
  1815.     ungetc( c, file_in );
  1816.     if (isalpha( c ))  return( TRUE );
  1817.   }
  1818.  
  1819.   return( FALSE );
  1820. }
  1821. /*****************************************************************************
  1822.   FUNCTION : getSymbol 
  1823.  
  1824.   PURPOSE  : 
  1825.   NOTES    : 
  1826.  
  1827.   RETURNS  : 
  1828.   UPDATE   : 
  1829. ******************************************************************************/
  1830.  
  1831. static bool  getSymbol(char *symbol)
  1832. {
  1833.   register int  c;
  1834.   register char  *s_ptr;
  1835.  
  1836.   do  {
  1837.     c = getc( file_in );
  1838.     if (c == '\n')  lineno++;
  1839.   }
  1840.   while ( isspace( c ) );
  1841.  
  1842.   if (c == EOF)  {
  1843.     KernelErrorCode = KRERR_EOF;
  1844.     return( FALSE );
  1845.   }
  1846.   else  {
  1847.     s_ptr = symbol;
  1848.     while (isgraph( c ))  {
  1849.       if ((c == ',') || (c == '|'))  break;
  1850.       *s_ptr++ = c;
  1851.       c = getc( file_in );
  1852.     }
  1853.  
  1854.     ungetc( c, file_in );
  1855.     *s_ptr = EOS;
  1856.     if (s_ptr == symbol)  {
  1857.       KernelErrorCode = KRERR_FILE_SYNTAX;
  1858.       return( FALSE );
  1859.     }
  1860.     return( TRUE );
  1861.   }
  1862. }
  1863. /*****************************************************************************
  1864.   FUNCTION : getSection 
  1865.  
  1866.   PURPOSE  : 
  1867.   NOTES    : 
  1868.  
  1869.   RETURNS  : 
  1870.   UPDATE   : 
  1871. ******************************************************************************/
  1872.  
  1873. static char  *getSection(char *line, int *title_no)
  1874. {
  1875.   int   i;
  1876.   char  *s1_ptr, *s2_ptr;
  1877.  
  1878.  
  1879.   if ( !skipComments() )
  1880.     {  /* EOF  */
  1881.     *title_no = -2;
  1882.     return( NULL );
  1883.   }
  1884.  
  1885.   if (fgets( line, LIN_MAX, file_in ) == NULL)
  1886.     {  /*  I/O error  */
  1887.     *title_no = -3;
  1888.     return( NULL );
  1889.   }
  1890.  
  1891.   for (i = 0; i < NoOfTitles; i++)  {
  1892.     s1_ptr = line;
  1893.     s2_ptr = title[ i ];
  1894.     while (*s2_ptr != EOS)
  1895.       {  /* compare strings, don't examine white space  */
  1896.       if (*s1_ptr == ' ') s1_ptr++;
  1897.       if (*s2_ptr == ' ') s2_ptr++;
  1898.       if (*s1_ptr++ != *s2_ptr++)  break;
  1899.  
  1900.       if (*s2_ptr == EOS)
  1901.     {   /*    strings are equal   */
  1902.     *title_no = i;
  1903.     return( s1_ptr );
  1904.       }
  1905.     }
  1906.   }
  1907.  
  1908.  
  1909.   *title_no = -1;  /*  title not found  */
  1910.   return( NULL );
  1911. }
  1912.  
  1913. /*****************************************************************************
  1914.   FUNCTION : matchHead
  1915.  
  1916.   PURPOSE  : read /dev/null
  1917.   NOTES    : 
  1918.  
  1919.   RETURNS  : 
  1920.   UPDATE   : 
  1921. ******************************************************************************/
  1922.  
  1923. static bool  matchHead(int N)
  1924. {
  1925.   register int  c;
  1926.   int   i;
  1927.  
  1928.  
  1929.   c = getc( file_in );
  1930.   if (c != '-')  {
  1931.     ungetc( c, file_in );
  1932.     return( FALSE );
  1933.   }
  1934.  
  1935.   for (i = 0; i < N; i++)  {
  1936.     c = getc( file_in );
  1937.     if (c != '-')
  1938.       return( FALSE );
  1939.  
  1940.     do
  1941.       c = getc( file_in );
  1942.     while ( c == '-' );
  1943.  
  1944.     if (c != '|')  {  KernelErrorCode = KRERR_FILE_SYNTAX;  return( FALSE );  }
  1945.   }
  1946.  
  1947.   c = getc( file_in );
  1948.   if (c != '-')  {  KernelErrorCode = KRERR_FILE_SYNTAX;  return( FALSE );  }
  1949.  
  1950.   do
  1951.     c = getc( file_in );
  1952.   while ( c == '-' );
  1953.  
  1954.   if (c == EOF)  {  KernelErrorCode = KRERR_EOF;  return( FALSE ); }
  1955.   ungetc( c, file_in );
  1956.  
  1957.   if ( !get_nl() )  return( FALSE );
  1958.  
  1959.   return( TRUE );
  1960. }
  1961.  
  1962. /*****************************************************************************
  1963.   FUNCTION : matchHead2 
  1964.  
  1965.   PURPOSE  : 
  1966.   NOTES    : 
  1967.  
  1968.   RETURNS  : 
  1969.   UPDATE   : 
  1970. ******************************************************************************/
  1971.  
  1972. static bool  matchHead2(int N)
  1973. {
  1974.   if (!skipSpace())  return( FALSE );
  1975.  
  1976.   return( matchHead(N) );
  1977. }
  1978.  
  1979.  
  1980. /*****************************************************************************
  1981.   FUNCTION : my_strstr 
  1982.  
  1983.   PURPOSE  : Find the first occurrence of find in s.
  1984.              (slow version)
  1985.   NOTES    : 
  1986.  
  1987.   RETURNS  : 
  1988.   UPDATE   : 
  1989. ******************************************************************************/
  1990. static char  *my_strstr(char *s, char *find)
  1991. {
  1992.   register char c, sc;
  1993.   register size_t len;
  1994.  
  1995.   if ((c = *find++) != 0)  {
  1996.     len = strlen(find);
  1997.     do  {
  1998.       do  {
  1999.     if ((sc = *s++) == 0)    return (NULL);
  2000.       }
  2001.       while (sc != c);
  2002.     }
  2003.     while (strncmp(s, find, len) != 0);
  2004.     s--;
  2005.   }
  2006.  
  2007.   return ((char *) s);
  2008. }
  2009.  
  2010.  
  2011. /*****************************************************************************
  2012.   FUNCTION : krio_readHeader 
  2013.  
  2014.   PURPOSE  : 
  2015.   NOTES    : 
  2016.  
  2017.   RETURNS  : 
  2018.   UPDATE   : 
  2019. ******************************************************************************/
  2020.  
  2021. static void  krio_readHeader(char *netfile_version, char *net_name, 
  2022.                  char *learn_func, char *update_func, 
  2023.                  int *no_of_units, int *no_of_connect, 
  2024.                  int *no_of_unitTypes, int *no_of_siteTypes)
  2025. {
  2026.   char  *cursor;
  2027.   int   ret_code,  i, no_of_scan_params,
  2028.         title_no;
  2029.  
  2030.  
  2031.   ret_code = 1;
  2032.  
  2033.   /*  get file version  */
  2034.   cursor = getSection( fmt_shape1, &title_no );
  2035.   if ((cursor == NULL) || (title_no != 0))  {
  2036.     /*  "SNNS network definition file" not found  */
  2037.     KernelErrorCode = KRERR_FILE_FORMAT;
  2038.     return;
  2039.   }
  2040.   if (sscanf( cursor, "%s", netfile_version ) != 1)  {
  2041.     /*  version string not found */
  2042.     KernelErrorCode = KRERR_FILE_FORMAT;
  2043.     return;
  2044.   }
  2045.  
  2046.   /*  determine version number of the network file  */
  2047.   if (my_strstr( netfile_version, KERNEL3D_NETFILE_VERSION ) != NULL)
  2048.     NetfileVersion = 1;
  2049.   else
  2050.     NetfileVersion = 0;
  2051.  
  2052.   if (my_strstr( netfile_version, NETFILE_VERSION ) != NULL ||
  2053.       my_strstr( netfile_version, NETFILE_VERSION2 ) != NULL)
  2054.     /*  current netfile version  */
  2055.     no_of_scan_params = 9;
  2056.   else
  2057.     no_of_scan_params = 8;
  2058.  
  2059.   for (i = 0; i < no_of_scan_params; i++)  {
  2060.     if ( (cursor = getSection( fmt_shape1, &title_no )) == NULL)  return;
  2061.  
  2062.     switch (title_no)  {
  2063.       case  -3:  /*  Physical I/O error  */
  2064.         KernelErrorCode = KRERR_IO;
  2065.         return;
  2066.       case  -2:  /*  unexpected EOF  */ 
  2067.         KernelErrorCode = KRERR_EOF;
  2068.         return;
  2069.       case  -1:  /*  not found  */ 
  2070.         KernelErrorCode = KRERR_FILE_FORMAT;  /*  Incompatible file format  */
  2071.         return;
  2072.       case  1:  /*  "generated at"  */
  2073.         break;
  2074.       case  2:  /*  network name"  */
  2075.         ret_code = sscanf( cursor, " :%s", net_name );
  2076.         if ((ret_code != 1) && (ret_code != 0))  {
  2077.           KernelErrorCode = KRERR_FILE_SYNTAX;
  2078.           return;
  2079.         }
  2080.         if (ret_code == 0) {
  2081.           *net_name = EOS;
  2082.           ret_code = 1;
  2083.         }
  2084.         break;
  2085.       case  3:  /*  "no. of units"  */
  2086.         ret_code = sscanf( cursor, " :%d", no_of_units );
  2087.         break; 
  2088.       case  4:  /*  "no. of connections"  */
  2089.         ret_code = sscanf( cursor, " :%d", no_of_connect );
  2090.         break;
  2091.       case  5:  /*  "no. of unit types"  */
  2092.         ret_code = sscanf( cursor, " :%d", no_of_unitTypes );
  2093.         break;
  2094.       case  6:  /*  "no. of site types"  */
  2095.         ret_code = sscanf( cursor, " :%d", no_of_siteTypes );
  2096.         break;
  2097.       case  7:  /*  "learning function"  */
  2098.         ret_code = sscanf( cursor, " :%s\n", learn_func );
  2099.         if ((ret_code != 1) && (ret_code != 0))  {
  2100.           KernelErrorCode = KRERR_FILE_SYNTAX;
  2101.           return;
  2102.         }
  2103.         if (ret_code == 0)  {
  2104.           *learn_func = '\0';
  2105.           ret_code = 1;
  2106.         }
  2107.         break;
  2108.       case 14:  /*  "source files"  */
  2109.         break;
  2110.       case  16:  /*  "update function"  */
  2111.         ret_code = sscanf( cursor, " :%s\n", update_func );
  2112.         if ((ret_code != 1) && (ret_code != 0))  {
  2113.           KernelErrorCode = KRERR_FILE_SYNTAX;
  2114.           return;
  2115.         }
  2116.  
  2117.         if (ret_code == 0)  {
  2118.           *update_func = '\0';
  2119.           ret_code = 1;
  2120.         }
  2121.         break;
  2122.       default:
  2123.         KernelErrorCode = KRERR_FILE_FORMAT;  /*  Incompatible file format  */
  2124.         return;
  2125.      }
  2126.  
  2127.    switch (ret_code)  {
  2128.      case 1:    /*  one argument matched  */
  2129.        break;
  2130.      case EOF:  /*  unexpected EOF  */
  2131.        KernelErrorCode = KRERR_EOF;
  2132.        return;
  2133.      default:   /*  Syntax error at line  */
  2134.        KernelErrorCode = KRERR_FILE_SYNTAX;
  2135.        return;
  2136.      }
  2137.  
  2138.    lineno++;
  2139.    }
  2140.  
  2141. }
  2142.  
  2143. /*****************************************************************************
  2144.   FUNCTION : str_to_Ttype 
  2145.  
  2146.   PURPOSE  : 
  2147.   NOTES    : 
  2148.  
  2149.   RETURNS  : 
  2150.   UPDATE   : 
  2151. ******************************************************************************/
  2152.  
  2153. static int  str_to_Ttype(char *str)
  2154. {
  2155.   if (strcmp (str, "i" ) == 0) return (INPUT    ) ;
  2156.   if (strcmp (str, "o" ) == 0) return (OUTPUT   ) ;
  2157.   if (strcmp (str, "h" ) == 0) return (HIDDEN   ) ;
  2158.   if (strcmp (str, "d" ) == 0) return (DUAL     ) ;
  2159.   if (strcmp (str, "s" ) == 0) return (SPECIAL  ) ;
  2160.   if (strcmp (str, "si") == 0) return (SPECIAL_I) ;
  2161.   if (strcmp (str, "so") == 0) return (SPECIAL_O) ;
  2162.   if (strcmp (str, "sh") == 0) return (SPECIAL_H) ;
  2163.   if (strcmp (str, "sd") == 0) return (SPECIAL_D) ;
  2164.   return( 0 );
  2165. }
  2166.  
  2167. /*****************************************************************************
  2168.   FUNCTION : krio_readSiteDefinitions 
  2169.  
  2170.   PURPOSE  : 
  2171.   NOTES    : 
  2172.  
  2173.   RETURNS  : 
  2174.   UPDATE   : 
  2175. ******************************************************************************/
  2176.  
  2177. static void  krio_readSiteDefinitions(void)
  2178. {
  2179.   if ( !skipComments() )  return;
  2180.   if ((fscanf( file_in, headers[0] ) != 0) ||
  2181.       !matchHead2( 1 ) )  {
  2182.     KernelErrorCode = KRERR_FILE_SYNTAX;
  2183.     return;
  2184.   }
  2185.  
  2186.   NoOfSiteTypes = 0;
  2187.   while (TRUE)  {
  2188.     if (matchHead2( 1 )) return;
  2189.     if (!skipComments())  return;
  2190.  
  2191.     if (!getSymbol( fmt_shape1 ))  return;
  2192.  
  2193.     /*  skip "|" character  */
  2194.     if (!skip_pipe())  return;
  2195.  
  2196.     if (!getSymbol( fmt_shape2 ))  return;
  2197.  
  2198.     if (krui_createSiteTableEntry( fmt_shape1, fmt_shape2 ) != KRERR_NO_ERROR)
  2199.       return;
  2200.  
  2201.     NoOfSiteTypes++;
  2202.   }
  2203. }
  2204.  
  2205. /*****************************************************************************
  2206.   FUNCTION : krio_readTypeDefinitions 
  2207.  
  2208.   PURPOSE  : 
  2209.   NOTES    : 
  2210.  
  2211.   RETURNS  : 
  2212.   UPDATE   : 
  2213. ******************************************************************************/
  2214.  
  2215. static void  krio_readTypeDefinitions(void)
  2216. {
  2217.   int  no_of_sites;
  2218.   SymbolType  *site_names = NULL;
  2219.   char  * *site_name_ptrs;
  2220.  
  2221.  
  2222.   NoOfUnitTypes = 0;
  2223.  
  2224.   if ( !skipComments() )  return;
  2225.   if ((fscanf( file_in, headers[1] ) != 0) ||
  2226.       !matchHead2( 3 ) )  {
  2227.     KernelErrorCode = KRERR_FILE_SYNTAX;
  2228.     return;
  2229.   }
  2230.  
  2231.   if (NoOfSiteTypes > 0)  {
  2232.     site_names = (SymbolType *) 
  2233.     calloc( (unsigned int) NoOfSiteTypes, sizeof (SymbolType) );
  2234.     site_name_ptrs = (char * *) 
  2235.     calloc( (unsigned int) NoOfSiteTypes, sizeof (site_name_ptrs) );
  2236.     if (site_names == NULL || site_name_ptrs == NULL)  {
  2237.       KernelErrorCode = KRERR_INSUFFICIENT_MEM;
  2238.       return;
  2239.     }
  2240.   }
  2241.  
  2242.   while (TRUE)  {
  2243.     if ( matchHead2( 3 ) )  break;
  2244.     if ( !skipComments() )  break;
  2245.  
  2246.     /*  read unit type name, activation and output function  */
  2247.     if (fscanf( file_in, "%s | %s | %s",
  2248.                 fmt_shape1, fmt_shape2,  fmt_shape3 ) != 3)  {
  2249.       KernelErrorCode = KRERR_FILE_SYNTAX;
  2250.       return;
  2251.     }
  2252.  
  2253.     /*  skip "|" character  */
  2254.     if (!skip_pipe())  return;
  2255.  
  2256.     NoOfUnitTypes++;
  2257.  
  2258.     if (get_nl())  {
  2259.       /*  no sites  */
  2260.       if (krui_createFTypeEntry( fmt_shape1, fmt_shape2,  fmt_shape3,
  2261.                                  0, site_name_ptrs ) != KRERR_NO_ERROR)
  2262.       return;
  2263.       continue;
  2264.     }
  2265.  
  2266.     no_of_sites = 0;
  2267.     while (TRUE)  {
  2268.       if (!getSymbol( site_names[ no_of_sites ] ))  return;
  2269.  
  2270.       site_name_ptrs[ no_of_sites ] = site_names[ no_of_sites ];
  2271.       no_of_sites++;
  2272.       if ( !comma() )  break;
  2273.       if (no_of_sites > NoOfSiteTypes)  {
  2274.         KernelErrorCode = KRERR_FILE_SYNTAX;
  2275.         return;
  2276.       }
  2277.     }
  2278.  
  2279.     if (krui_createFTypeEntry( fmt_shape1, fmt_shape2,  fmt_shape3,
  2280.                                no_of_sites, site_name_ptrs ) != KRERR_NO_ERROR)
  2281.       return;
  2282.   }
  2283.  
  2284.   if (site_names != NULL)  {
  2285.     free( (char *) site_names );
  2286.     free( (char *) site_name_ptrs );
  2287.   }
  2288. }
  2289.  
  2290.  
  2291. /*****************************************************************************
  2292.   FUNCTION :  krio_readDefaultDefinitions
  2293.  
  2294.   PURPOSE  : 
  2295.   NOTES    : 
  2296.  
  2297.   RETURNS  : 
  2298.   UPDATE   : 
  2299. ******************************************************************************/
  2300.  
  2301. static void  krio_readDefaultDefinitions(void)
  2302. {
  2303.   FlintType  act, bias;
  2304.   int  st, subnet_no, layer_no;
  2305.  
  2306.  
  2307.   if ( !skipComments() )  return;
  2308.   if ((fscanf( file_in, headers[2] ) != 0) ||
  2309.       !matchHead2( 6 ) )  {
  2310.     KernelErrorCode = KRERR_FILE_SYNTAX;
  2311.     return;
  2312.   }
  2313.  
  2314.   if (fscanf( file_in, "%f | %f | %s | %d | %d | %s | %s",
  2315.               &act, &bias, fmt_shape1, &subnet_no, &layer_no,
  2316.               fmt_shape2, fmt_shape3 ) != 7)  {
  2317.     KernelErrorCode = KRERR_FILE_SYNTAX;
  2318.     return;
  2319.   }
  2320.  
  2321.   if ( (st = str_to_Ttype( fmt_shape1 )) == 0)  {
  2322.     KernelErrorCode = KRERR_TTYPE;
  2323.     return;
  2324.   }
  2325.  
  2326.   if (krui_setUnitDefaults( act, bias, st, subnet_no, layer_no,
  2327.                             fmt_shape2, fmt_shape3 )  != KRERR_NO_ERROR)
  2328.     return;
  2329.  
  2330.   if ( !matchHead2( 6 ) )  KernelErrorCode = KRERR_FILE_SYNTAX;
  2331. }
  2332.  
  2333. /*****************************************************************************
  2334.   FUNCTION : krio_readUnitDefinitions 
  2335.  
  2336.   PURPOSE  : 
  2337.   NOTES    : 
  2338.  
  2339.   RETURNS  : 
  2340.   UPDATE   : 
  2341. ******************************************************************************/
  2342.  
  2343. static void  krio_readUnitDefinitions(void)
  2344. {
  2345.   struct PosType  pos;
  2346.   FlintType  fp;
  2347.   int   unit_no, def_unit_no, st, x, y, z;
  2348.   bool  is_ftype_unit;
  2349.  
  2350.  
  2351.   if ( !skipComments() )  return;
  2352.   if ((fscanf( file_in, headers[3] ) != 0) ||
  2353.       !matchHead2( 9 ) )  {
  2354.     KernelErrorCode = KRERR_FILE_SYNTAX;
  2355.     return;
  2356.   }
  2357.  
  2358.   def_unit_no = 0;
  2359.   while (TRUE)  {
  2360.     if ( matchHead2( 9 ) )  return;
  2361.     if ( !skipComments() )  return;
  2362.  
  2363.     /*  read unit no.  */
  2364.     if (fscanf( file_in, "%d", &unit_no ) != 1)  {
  2365.       KernelErrorCode = KRERR_FILE_SYNTAX;
  2366.       return;
  2367.     }
  2368.     if (unit_no != ++def_unit_no)  {
  2369.       KernelErrorCode = KRERR_UNIT_NO;
  2370.       return;
  2371.     }
  2372.  
  2373.     /*  skip "|" character  */
  2374.     if (!skip_pipe())  return;
  2375.  
  2376.     /*  read unit type name, if exist  */
  2377.     if (!get_pipe())  {
  2378.       if (KernelErrorCode != KRERR_NO_ERROR)  return;
  2379.       /*  read unit type name  */
  2380.       if (fscanf( file_in, "%s", fmt_shape1 ) != 1)  {
  2381.         KernelErrorCode = KRERR_FILE_SYNTAX;
  2382.         return;
  2383.       }
  2384.       
  2385.       krui_createFTypeUnit( fmt_shape1 );
  2386.       if (KernelErrorCode != KRERR_NO_ERROR)  return;
  2387.       /*  skip next "|" character  */
  2388.       if (!skip_pipe())  return;
  2389.  
  2390.       is_ftype_unit = TRUE;
  2391.     }
  2392.     else  {
  2393.       if (krui_createDefaultUnit() != unit_no)  {
  2394.         KernelErrorCode = KRERR_MALLOC1;
  2395.         return;
  2396.       }
  2397.       is_ftype_unit = FALSE;
  2398.     }
  2399.  
  2400.     /*  read unit name, if exist  */
  2401.     if (!get_pipe())  {
  2402.       if (KernelErrorCode != KRERR_NO_ERROR)  return;
  2403.       /*  read unit name  */
  2404.       if (fscanf( file_in, "%s", fmt_shape1 ) != 1)  {
  2405.         KernelErrorCode = KRERR_FILE_SYNTAX;
  2406.         return;
  2407.       }
  2408.  
  2409.       if (krui_setUnitName(def_unit_no, fmt_shape1) != KRERR_NO_ERROR) return;
  2410.       /*  skip next "|" character  */
  2411.       if (!skip_pipe())  return;
  2412.     }
  2413.  
  2414.     /*  read unit's activation value, if exist  */
  2415.     if (!get_pipe())  {
  2416.       if (KernelErrorCode != KRERR_NO_ERROR)  return;
  2417.       /*  read unit activation value  */
  2418.       if (fscanf( file_in, "%f", &fp ) != 1)  {
  2419.         KernelErrorCode = KRERR_FILE_SYNTAX;
  2420.         return;
  2421.       }
  2422.       krui_setUnitInitialActivation( def_unit_no, fp );
  2423.       krui_setUnitActivation( def_unit_no, fp );
  2424.       /*  skip next "|" character  */
  2425.       if (!skip_pipe())  return;
  2426.     }
  2427.  
  2428.     /*  read unit's bias value, if exist  */
  2429.     if (!get_pipe())  {
  2430.       if (KernelErrorCode != KRERR_NO_ERROR)  return;
  2431.       /*  read unit bias value  */
  2432.       if (fscanf( file_in, "%f", &fp ) != 1)  {
  2433.         KernelErrorCode = KRERR_FILE_SYNTAX;
  2434.         return;
  2435.       }
  2436.       krui_setUnitBias( def_unit_no, fp );
  2437.       /*  skip next "|" character  */
  2438.       if (!skip_pipe())  return;
  2439.     }
  2440.  
  2441.     /*  read unit's topologic type, if exist  */
  2442.     if (!get_pipe())  {
  2443.       if (KernelErrorCode != KRERR_NO_ERROR)  return;
  2444.       /*  read unit's topologic type  */
  2445.       if (fscanf( file_in, "%s", fmt_shape1 ) != 1)  {
  2446.         KernelErrorCode = KRERR_FILE_SYNTAX;
  2447.         return;
  2448.       }
  2449.       if ( (st = str_to_Ttype( fmt_shape1 )) == 0)  {
  2450.         KernelErrorCode = KRERR_TTYPE;
  2451.         return;
  2452.       }
  2453.  
  2454.       if (krui_setUnitTType( def_unit_no, st ) != KRERR_NO_ERROR)  return;
  2455.       /*  skip next "|" character  */
  2456.       if (!skip_pipe())  return;
  2457.     }
  2458.  
  2459.     /*  read unit position  */
  2460.     switch (NetfileVersion)  {
  2461.       case 0:
  2462.         if (fscanf( file_in, "%d , %d", &x, &y ) != 2)  {
  2463.           KernelErrorCode = KRERR_FILE_SYNTAX;
  2464.           return;
  2465.         }
  2466.         pos.x = (short) x;
  2467.         pos.y = (short) y;
  2468. #ifdef KERNEL3D
  2469.         pos.z = (short) 0;
  2470. #endif
  2471.         krui_setUnitPosition( def_unit_no, &pos );
  2472.  
  2473.         break;
  2474.  
  2475.       case 1:
  2476.         if (fscanf( file_in, "%d , %d, %d", &x, &y, &z ) != 3)  {
  2477.           KernelErrorCode = KRERR_FILE_SYNTAX;
  2478.           return;
  2479.         }
  2480.         pos.x = (short) x;
  2481.         pos.y = (short) y;
  2482. #ifdef KERNEL3D
  2483.         pos.z = (short) z;
  2484. #endif
  2485.         krui_setUnitPosition( def_unit_no, &pos );
  2486.  
  2487.         break;
  2488.     }
  2489.  
  2490.     /*  skip "|" character  */
  2491.     if (!skip_pipe())  return;
  2492.  
  2493.     if (is_ftype_unit)  {
  2494.       /*  skip 2 "|" characters  */
  2495.      if (!skip_pipe())  return;
  2496.      if (!skip_pipe())  return;
  2497.     }
  2498.     else  {
  2499.       /*  read unit's activation function, if exist  */
  2500.       if (!get_pipe())  {
  2501.         if (KernelErrorCode != KRERR_NO_ERROR)  return;
  2502.         /*  read unit's activation function  */
  2503.         if (fscanf( file_in, "%s", fmt_shape1 ) != 1)  {
  2504.           KernelErrorCode = KRERR_FILE_SYNTAX;
  2505.           return;
  2506.         }
  2507.         if (krui_setUnitActFunc( def_unit_no, fmt_shape1 ) != KRERR_NO_ERROR)
  2508.           return;
  2509.         /*  skip next "|" character  */
  2510.         if (!skip_pipe())  return;
  2511.       }
  2512.  
  2513.       /*  read unit's output function, if exist  */
  2514.       if (!get_pipe())  {
  2515.         if (KernelErrorCode != KRERR_NO_ERROR)  return;
  2516.         /*  read unit's output function  */
  2517.         if (fscanf( file_in, "%s", fmt_shape1 ) != 1)  {
  2518.           KernelErrorCode = KRERR_FILE_SYNTAX;
  2519.           return;
  2520.         }
  2521.         if (krui_setUnitOutFunc( def_unit_no, fmt_shape1 ) != KRERR_NO_ERROR)
  2522.           return;
  2523.         /*  skip next "|" character  */
  2524.         if (!skip_pipe())  return;
  2525.       }
  2526.     }
  2527.  
  2528.     if (get_alpha())  {
  2529.       /*  a site name was detected  */
  2530.       if (krui_setCurrentUnit( def_unit_no ) != KRERR_NO_ERROR)  return;
  2531.  
  2532.       /*  get site names  */
  2533.       while (TRUE)  {
  2534.         if (!getSymbol( fmt_shape1 ))  {
  2535.           KernelErrorCode = KRERR_FILE_SYNTAX;
  2536.           return;
  2537.         }
  2538.         if (krui_addSite( fmt_shape1 ) != KRERR_NO_ERROR)  return;
  2539.  
  2540.         if ( !comma() )  break;
  2541.       }
  2542.     }
  2543.   }
  2544. }
  2545. /*****************************************************************************
  2546.   FUNCTION : krio_readConnectionDefs 
  2547.  
  2548.   PURPOSE  : 
  2549.   NOTES    : 
  2550.  
  2551.   RETURNS  : 
  2552.   UPDATE   : 
  2553. ******************************************************************************/
  2554.  
  2555. static void  krio_readConnectionDefs(void)
  2556. {
  2557.   FlintType  weight;
  2558.   int   unit_no, src_unit_no;
  2559.   bool  new_unit, unit_has_sites;
  2560.  
  2561.  
  2562.   if ( !skipComments() )  return;
  2563.   if ((fscanf( file_in, headers[4] ) != 0) ||
  2564.      (!matchHead2( 2 )) )  {
  2565.     KernelErrorCode = KRERR_FILE_SYNTAX;
  2566.     return;
  2567.   }
  2568.  
  2569.   new_unit = TRUE;
  2570.   unit_has_sites = FALSE;
  2571.  
  2572.   while (TRUE)  {
  2573.     if ( matchHead2( 2 ) )  return;
  2574.     if ( !skipComments() )  return;
  2575.  
  2576.     if (new_unit)  {
  2577.       if (fscanf( file_in, "%d", &unit_no ) != 1)  {
  2578.         KernelErrorCode = KRERR_FILE_SYNTAX;
  2579.         return;
  2580.       }
  2581.  
  2582.       if (krui_setCurrentUnit( unit_no ) != KRERR_NO_ERROR)  return;
  2583.  
  2584.       /*  skip "|" character  */
  2585.       if (!skip_pipe())  return;
  2586.     }
  2587.  
  2588.     /*  test for occurence of the "|" character, if exist the unit
  2589.         has no sites  */
  2590.     if (unit_has_sites || !get_pipe())  {
  2591.       if (KernelErrorCode != KRERR_NO_ERROR)  return;
  2592.       /*  read site name  */
  2593.       if (fscanf( file_in, "%s", fmt_shape1 ) != 1)  {
  2594.         KernelErrorCode = KRERR_FILE_SYNTAX;
  2595.         return;
  2596.       }
  2597.  
  2598.       if (krui_setSite( fmt_shape1 ) != KRERR_NO_ERROR)  return;
  2599.       unit_has_sites = TRUE;
  2600.  
  2601.       /* following two lines were taken off between v1.3 and v1.5 of
  2602.          this file. the result was that when reading artmap nets, there
  2603.          occured a syntax error
  2604.       */
  2605.       /* skip "|" character */
  2606.       if (!skip_pipe()) return;
  2607.  
  2608.     }
  2609.     else
  2610.       unit_has_sites = FALSE;
  2611.  
  2612.     while (TRUE)  {
  2613.       /*  read link weights  */
  2614.       if (fscanf( file_in, "%d : %f", &src_unit_no, &weight ) != 2)  {
  2615.         KernelErrorCode = KRERR_FILE_SYNTAX;
  2616.         return;
  2617.       }
  2618.  
  2619.       if (krui_createLink( src_unit_no, weight ) != KRERR_NO_ERROR)  return;
  2620.  
  2621.       if ( !comma() )  break;
  2622.     }
  2623.  
  2624.     if (unit_has_sites)  {
  2625.       if (get_alpha())  {
  2626.         /*  a new site name was found  */
  2627.         new_unit = FALSE;
  2628.       }
  2629.       else  {
  2630.         if (KernelErrorCode != KRERR_NO_ERROR)  return;
  2631.         /*  a digit was read -> a new unit number was found  */
  2632.         new_unit = TRUE;
  2633.         unit_has_sites = FALSE;
  2634.       }
  2635.     }
  2636.   }
  2637. }
  2638.  
  2639. /*****************************************************************************
  2640.   FUNCTION : krio_readSubnetDefs 
  2641.  
  2642.   PURPOSE  : 
  2643.   NOTES    : 
  2644.  
  2645.   RETURNS  : 
  2646.   UPDATE   : 
  2647. ******************************************************************************/
  2648.  
  2649. static void  krio_readSubnetDefs(void)
  2650. {
  2651.   int   unit_no, subnet_no;
  2652.  
  2653.  
  2654.   if ( !skipComments() )  return;
  2655.   if ((fscanf( file_in, headers[5] ) != 0) ||
  2656.       !matchHead2( 1 ) )  {
  2657.     KernelErrorCode = KRERR_FILE_SYNTAX;
  2658.     return;
  2659.   }
  2660.  
  2661.   while (TRUE)  {
  2662.     if (matchHead2( 1 )) return;
  2663.     if ( !skipComments() )  return;
  2664.     if (fscanf( file_in, "%d", &subnet_no ) != 1)  {
  2665.       KernelErrorCode = KRERR_FILE_SYNTAX;
  2666.       return;
  2667.     }
  2668.  
  2669.     if ( !get_pipe() )  {
  2670.       KernelErrorCode = KRERR_FILE_SYNTAX;
  2671.       return;
  2672.     }
  2673.  
  2674.     while (TRUE)  {
  2675.       if (fscanf( file_in, "%d", &unit_no ) != 1)  {
  2676.         KernelErrorCode = KRERR_FILE_SYNTAX;
  2677.         return;
  2678.       }
  2679.       if (kr_getUnitPtr( unit_no ) == NULL)  return;
  2680.  
  2681.       krui_setUnitSubnetNo( unit_no, subnet_no );
  2682.  
  2683.       if ( !comma() )  break;
  2684.     }
  2685.   }
  2686. }
  2687.  
  2688. /*****************************************************************************
  2689.   FUNCTION : krio_readLayerDefs 
  2690.  
  2691.   PURPOSE  : 
  2692.   NOTES    : 
  2693.  
  2694.   RETURNS  : 
  2695.   UPDATE   : 
  2696. ******************************************************************************/
  2697.  
  2698. static void  krio_readLayerDefs(void)
  2699. {
  2700.   int   unit_no, layer_no;
  2701.  
  2702.  
  2703.   if ( !skipComments() )  return;
  2704.   if ((fscanf( file_in, headers[6] ) != 0) ||
  2705.       !matchHead2( 1 ) )  {
  2706.     KernelErrorCode = KRERR_FILE_SYNTAX;
  2707.     return;
  2708.   }
  2709.  
  2710.   while (TRUE)  {
  2711.     if (matchHead2( 1 )) return;
  2712.     if ( !skipComments() )  return;
  2713.     if (fscanf( file_in, "%d", &layer_no ) != 1)  {
  2714.       KernelErrorCode = KRERR_FILE_SYNTAX;
  2715.       return;
  2716.     }
  2717.  
  2718.     if ( !get_pipe() )  {
  2719.       KernelErrorCode = KRERR_FILE_SYNTAX;
  2720.       return;
  2721.     }
  2722.  
  2723.     while (TRUE)  {
  2724.       if (fscanf( file_in, "%d", &unit_no ) != 1)  {
  2725.         KernelErrorCode = KRERR_FILE_SYNTAX;
  2726.         return;
  2727.       }
  2728.       if (kr_getUnitPtr( unit_no ) == NULL)  return;
  2729.  
  2730.       krui_setUnitLayerNo( unit_no, (unsigned short) layer_no );
  2731.  
  2732.       if ( !comma() )  break;
  2733.     }
  2734.   }
  2735. }
  2736.  
  2737. #ifdef KERNEL3D
  2738.  
  2739. /*****************************************************************************
  2740.   FUNCTION : readXYTransTable 
  2741.  
  2742.   PURPOSE  : read the XY-Tranlation Table from input file 
  2743.   NOTES    : 
  2744.  
  2745.   RETURNS  : 
  2746.   UPDATE   : 
  2747. ******************************************************************************/
  2748. static void  readXYTransTable(void)
  2749. {
  2750.   int x, y, z;
  2751.  
  2752.  
  2753.   kr_xyTransTable( OP_TRANSTABLE_CLEAR, &x, &y, 0 );
  2754.  
  2755.   if ( !skipComments() )  return;
  2756.   if ((fscanf( file_in, headers[7] ) != 0) ||
  2757.       !matchHead2( 2 ) )  {
  2758.     KernelErrorCode = KRERR_FILE_SYNTAX;
  2759.     return;
  2760.   }
  2761.  
  2762.   while (TRUE)  {
  2763.     if (matchHead( 2 )) return;
  2764.     if ( !skipComments() )  return;
  2765.  
  2766.     if (fscanf( file_in, "%d | %d | %d", &x, &y, &z ) != 3)  {
  2767.       KernelErrorCode = KRERR_FILE_SYNTAX;
  2768.       return;
  2769.     }
  2770.     (void) skipSpace();
  2771.  
  2772.     kr_xyTransTable( OP_TRANSTABLE_SET, &x, &y, z );
  2773.   }
  2774. }
  2775.  
  2776. #endif
  2777.  
  2778. /*****************************************************************************
  2779.   FUNCTION : krio_readTimeDelayDefs
  2780.  
  2781.   PURPOSE  : 
  2782.   NOTES    : 
  2783.  
  2784.   RETURNS  : 
  2785.   UPDATE   : 
  2786. ******************************************************************************/
  2787. void krio_readTimeDelayDefs(void)
  2788. {
  2789.    int u_no,
  2790.        lln, 
  2791.        lun,
  2792.        toff,
  2793.        soff,
  2794.        conn_type,
  2795.        ret;
  2796.  
  2797.    struct Unit *unit_ptr;
  2798.  
  2799.   if ( !skipComments() )  return;
  2800.   if (fscanf( file_in, headers[8] ) != 0)
  2801.     {  KernelErrorCode = KRERR_FILE_SYNTAX;  return;  }
  2802.   if ( !matchHead2( 5 ) )
  2803.     {  KernelErrorCode = KRERR_FILE_SYNTAX;  return;  }
  2804.   
  2805.   while (TRUE)
  2806.     {
  2807.     if (matchHead2( 5 )) return;
  2808.     if ( !skipComments() )  return;
  2809.  
  2810.     ret = fscanf (file_in, "%4d |%4d |%4d |%5d |%5d |%6d", 
  2811.           &u_no, &lln, &lun, &toff, &soff, &conn_type);
  2812.     if (ret != 6)  {  KernelErrorCode = KRERR_FILE_SYNTAX;  return;  }
  2813.  
  2814.     unit_ptr = kr_getUnitPtr (u_no);
  2815.  
  2816.     unit_ptr->lln = lln;
  2817.     unit_ptr->lun = lun;
  2818.     unit_ptr->TD.target_offset = toff;
  2819.     unit_ptr->TD.source_offset = soff;
  2820.     unit_ptr->TD.td_connect_typ = conn_type;
  2821.     unit_ptr++;
  2822.     }
  2823. }   
  2824.  
  2825.  
  2826.  
  2827. /*****************************************************************************
  2828.   FUNCTION : krio_loadNet  
  2829.  
  2830.   PURPOSE  : load network from disk
  2831.   NOTES    : 
  2832.  
  2833.   RETURNS  : 
  2834.   UPDATE   : 
  2835. ******************************************************************************/
  2836. krui_err  krio_loadNet(char *filename, char **netname, char **netfile_version)
  2837. {
  2838.   static char  netname_str[81],
  2839.                netfile_version_str[81],
  2840.                learn_func[81],
  2841.                update_func[81];
  2842.  
  2843.   int  no_units, no_connect, no_unitT,
  2844.        no_siteT, title_no, status;
  2845.  
  2846.  
  2847.   KernelErrorCode = KRERR_NO_ERROR;
  2848.   lineno = status = 0;
  2849.  
  2850.   file_in = fopen( filename, "r" );
  2851.   if (file_in == NULL)  {
  2852.     KernelErrorCode = KRERR_FILE_OPEN;  /*  Can't open file  */
  2853.     goto end;
  2854.   }
  2855.  
  2856.   lineno = 1;
  2857.   if (NoOfUnits > 0)  krui_deleteNet();
  2858.  
  2859.   krio_readHeader( netfile_version_str, netname_str, learn_func, update_func,
  2860.                    &no_units, &no_connect, &no_unitT, &no_siteT );
  2861.   if (KernelErrorCode)  goto end;
  2862.  
  2863.   if(*learn_func != '\0')  {
  2864.     (void) krui_setLearnFunc( learn_func );
  2865.     if (KernelErrorCode)  goto end;
  2866.   }
  2867.   if(*update_func != '\0')  {
  2868.     (void)  krui_setUpdateFunc( update_func );
  2869.     if (KernelErrorCode)  goto end;
  2870.   }
  2871.  
  2872.   *netname = netname_str;
  2873.   *netfile_version = netfile_version_str;
  2874.  
  2875.   while ( getSection( fmt_shape1, &title_no ) != NULL )  {
  2876.     if (title_no >= 0)  lineno++;  /* increment line number */
  2877.  
  2878.     switch (title_no)  {
  2879.       case  -3:  /*  Physical I/O error  */
  2880.         KernelErrorCode = KRERR_IO;
  2881.         return( KernelErrorCode );
  2882.       case  -2:  /*   EOF  */
  2883.         if (status < 2)  KernelErrorCode = KRERR_EOF;  /*  unexpected EOF  */
  2884.         return( KernelErrorCode );
  2885.       case  -1:  /*  not found  */
  2886.         KernelErrorCode = KRERR_FILE_SYNTAX;  /*  Syntax error at line  */
  2887.         break;
  2888.       case  8:  /*  "site definition section"  */
  2889.     krio_readSiteDefinitions();
  2890.         break;
  2891.       case  9:  /*  "type definition section"  */
  2892.     krio_readTypeDefinitions();
  2893.         break;
  2894.       case  10:  /*  "unit definition section"  */
  2895.     (void) krui_allocateUnits( no_units );
  2896.     if (KernelErrorCode)  goto end;
  2897.  
  2898.         krio_readUnitDefinitions();
  2899.         status++;
  2900.         break;
  2901.       case  11:  /*  "connection definition section"  */
  2902.     krio_readConnectionDefs();
  2903.         status++;
  2904.         break;
  2905.       case  12:  /*  "subnet definition section"  */
  2906.     krio_readSubnetDefs();
  2907.         break;
  2908.       case  13:  /*  "unit default section"  */
  2909.     krio_readDefaultDefinitions();
  2910.         break;
  2911.       case  15:  /*  "layer definition section"  */
  2912.     krio_readLayerDefs();
  2913.         break;
  2914. #ifdef KERNEL3D
  2915.       case  17:  /*  "3D translation section"  */
  2916.     readXYTransTable();
  2917.         break;
  2918. #endif
  2919.       case  18:  /*  "time delay section"  */
  2920.         krio_readTimeDelayDefs ();
  2921.     break;
  2922.       default:
  2923.         KernelErrorCode = KRERR_FILE_FORMAT;  /*  Incompatible file format  */
  2924.         break;
  2925.     }
  2926.  
  2927.     if (KernelErrorCode)  break;
  2928.   }
  2929.  
  2930.   if (KernelErrorCode == KRERR_NO_ERROR)  lineno = 0;
  2931.  
  2932. end:
  2933.   if (file_in != NULL)
  2934.     fclose( file_in );
  2935.  
  2936.   return( KernelErrorCode );
  2937. }
  2938.  
  2939. /*#################################################
  2940.  
  2941. GROUP: Functions for Pattern Management
  2942.  
  2943. This group has been moved to kr_newpattern.c
  2944.  
  2945. #################################################*/
  2946.  
  2947. /*#################################################
  2948.  
  2949. GROUP: Functions for Result Management
  2950.  
  2951. #################################################*/
  2952. /*****************************************************************************
  2953.   FUNCTION : krio_saveResult 
  2954.  
  2955.   PURPOSE  : write result to disk 
  2956.   NOTES    : 
  2957.  
  2958.   RETURNS  : 
  2959.   UPDATE   : now the actual update function is used instead of 
  2960.              Topological_Order (M. Vogt, 20.02.93, necessary for TD networks)
  2961. ******************************************************************************/
  2962. krui_err krio_saveResult(char *filename, bool create, int startpattern, 
  2963.              int endpattern, bool includeinput, bool includeoutput)
  2964. {
  2965.   char    work_str[ LIN_MAX ];
  2966.   float param_array[5];
  2967.   struct Unit    *unit_ptr;
  2968.   long    clock;
  2969.   int  ret,  i, j;
  2970.   int  no_of_input_patterns, no_of_output_patterns;
  2971.   Patterns  in_pat, out_pat, save_in_pat;
  2972.   krui_err    temp_error;
  2973.   int start, end, i_size, o_size, in_pat_size;
  2974.   int pat,sub;
  2975.  
  2976.   lineno = 1;
  2977.   KernelErrorCode = KRERR_NO_ERROR;
  2978.  
  2979.   if (krui_getNoOfPatterns() == 0)
  2980.   {
  2981.     KernelErrorCode = KRERR_NO_PATTERNS;
  2982.     return( KernelErrorCode );
  2983.   }
  2984.  
  2985.   if (endpattern < startpattern || endpattern > krui_getNoOfPatterns())
  2986.   {
  2987.     return(KernelErrorCode = KRERR_PATTERN_NO);
  2988.   }
  2989.  
  2990.   /* calculate absolute numbers of first and last subpattern */
  2991.   KernelErrorCode = kr_initSubPatternOrder(startpattern-1,endpattern-1);
  2992.   if (KernelErrorCode != KRERR_NO_ERROR)
  2993.       return( KernelErrorCode );
  2994.  
  2995.   start = kr_AbsPosOfFirstSubPat(startpattern-1);
  2996.   end   = kr_AbsPosOfFirstSubPat(endpattern-1);
  2997.   end  += kr_NoOfSubPatPairs(endpattern-1)-1;
  2998.  
  2999.   if (create)
  3000.     file_out = fopen(filename, "w");
  3001.   else
  3002.     file_out = fopen(filename, "a");
  3003.   if (file_out == NULL)
  3004.   { /*  Can't open file  */
  3005.     KernelErrorCode = KRERR_FILE_OPEN;
  3006.     return( KernelErrorCode );
  3007.   }
  3008.  
  3009.   KernelErrorCode = KRERR_IO;
  3010.  
  3011.   /*  write header and version number  */
  3012.   ret = fprintf( file_out, resHeader[0], krio_getIOVersion() );
  3013.   RETCHKGTO( ret );
  3014.   lineno++;
  3015.  
  3016.   /*  write date  */
  3017.   clock = 1;
  3018.   (void) time( (time_t *) &clock);
  3019.  
  3020.   strcpy( work_str, resHeader[1] );
  3021.   strcat( work_str, " %s\n" );
  3022.   ret = fprintf( file_out, work_str, ctime( (time_t *) &clock) );
  3023.   RETCHKGTO( ret );
  3024.   lineno++;
  3025.  
  3026.   /*  write no. of patterns, input units, output units  */
  3027.   strcpy( work_str, resHeader[2] );
  3028.   strcat( work_str, resHeader[3] );
  3029.   strcat( work_str, resHeader[4] );
  3030.   ret = fprintf( file_out, work_str, end - start + 1, 
  3031.     krui_getNoOfInputUnits(), krui_getNoOfOutputUnits() );
  3032.   RETCHKGTO( ret );
  3033.   lineno += 3;
  3034.  
  3035.   /* write numbers of used patterns */
  3036.   strcpy( work_str, resHeader[5] );
  3037.   strcat( work_str, resHeader[6] );
  3038.   ret = fprintf( file_out, work_str, startpattern, endpattern);
  3039.   RETCHKGTO( ret );
  3040.   lineno += 2;
  3041.  
  3042.   /* write additional format information */
  3043.   if (includeinput)
  3044.   {
  3045.     ret = fprintf(file_out, resHeader[7]);
  3046.     RETCHKGTO( ret );
  3047.     lineno += 1;
  3048.   }
  3049.   if (includeoutput)
  3050.   {
  3051.     ret = fprintf(file_out, resHeader[8]);
  3052.     RETCHKGTO( ret );
  3053.     lineno += 1;
  3054.   }
  3055.  
  3056.   /* process network update for all subpattern */
  3057.   for(i=start; i<=end;i++){
  3058.     kr_getSubPatternByNo(&pat,&sub,i);
  3059.     in_pat = kr_getSubPatData(pat,sub,INPUT,&i_size);
  3060.     out_pat = kr_getSubPatData(pat,sub,OUTPUT,&o_size);
  3061.  
  3062.     if (in_pat == (Patterns) NULL || out_pat == (Patterns) NULL)
  3063.     goto end;
  3064.  
  3065.     if (o_size == 0 && includeoutput)
  3066.     {
  3067.     KernelErrorCode = KRERR_NP_NO_OUTPUT_PATTERN;
  3068.     goto end;
  3069.     }
  3070.  
  3071.     ret = fprintf( file_out, "#%d.%d\n", pat+1, sub+1 );
  3072.     RETCHKGTO( ret );
  3073.  
  3074.     if (includeinput)
  3075.     {
  3076.     save_in_pat = in_pat;
  3077.     for (j = 1; j <= i_size; j++)
  3078.         {
  3079.             sprintf( work_str, "%.5f", *in_pat );
  3080.             krio_cutTrailingZeros( work_str );
  3081.  
  3082.             if (j < i_size)
  3083.                 if (j % 10 == 0)  
  3084.             strcat( work_str, "\n" );
  3085.                 else
  3086.             strcat( work_str, " " );
  3087.    
  3088.         ret = fputs( work_str, file_out );
  3089.         RETCHKGTO( ret );  
  3090.  
  3091.         lineno++;
  3092.         in_pat++;
  3093.         }
  3094.     fputs( "\n", file_out );
  3095.     in_pat = save_in_pat;
  3096.     }
  3097.  
  3098.     if (includeoutput)
  3099.     {
  3100.         for (j = 1; j <= o_size; j++)
  3101.           {
  3102.               sprintf( work_str, "%.5f", *out_pat );
  3103.               krio_cutTrailingZeros( work_str );
  3104.  
  3105.               if (j < o_size)
  3106.             if (j % 10 == 0)  
  3107.             strcat( work_str, "\n" );
  3108.             else  
  3109.             strcat( work_str, " " );
  3110.  
  3111.         ret = fputs( work_str, file_out );
  3112.         RETCHKGTO( ret );  
  3113.  
  3114.         lineno++;
  3115.               out_pat++;
  3116.         }
  3117.     fputs( "\n", file_out );
  3118.     }
  3119.  
  3120.     /* activate input layer */
  3121.     in_pat_size = i_size;
  3122.     FOR_ALL_UNITS( unit_ptr )
  3123.     if ( IS_INPUT_UNIT( unit_ptr ) && UNIT_IN_USE( unit_ptr ))
  3124.         if (in_pat_size--)
  3125.         unit_ptr->act = *in_pat++;
  3126.  
  3127.     /* propagate network */
  3128.     if ((temp_error = krui_updateNet(param_array, 0)) != KRERR_NO_ERROR)
  3129.     {
  3130.     KernelErrorCode = temp_error;
  3131.     goto end;
  3132.     }
  3133.  
  3134.     /* write network output */
  3135.     j = 1;
  3136.     FOR_ALL_UNITS( unit_ptr )
  3137.         if UNIT_IN_USE( unit_ptr )
  3138.         {
  3139.             if IS_OUTPUT_UNIT( unit_ptr )
  3140.             {
  3141.         sprintf( work_str, "%.5f", unit_ptr->Out.output );
  3142.                   krio_cutTrailingZeros( work_str );
  3143.         if (j < o_size)
  3144.                 if (j % 10 == 0)  
  3145.             strcat( work_str, "\n" );
  3146.                 else  
  3147.             strcat( work_str, " " );
  3148.         j++;
  3149.             ret = fputs( work_str, file_out );
  3150.             RETCHKGTO( ret );  
  3151.  
  3152.             lineno++;
  3153.             }
  3154.         }
  3155.     fputs( "\n", file_out );
  3156.   }
  3157.  
  3158.  
  3159. end:
  3160.   if (KernelErrorCode == KRERR_NO_ERROR)
  3161.       lineno = 0;
  3162.   if (fclose(file_out) != 0 && KernelErrorCode == KRERR_NO_ERROR)
  3163.     KernelErrorCode = KRERR_IO;
  3164.  
  3165.   return KernelErrorCode;
  3166. }
  3167.  
  3168.  
  3169.